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 112 by alloc, Thu Feb 22 00:37:39 2007 UTC vs.
Revision 173 by alloc, Wed May 2 13:19:40 2007 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 31 | Line 30 | type
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  
# Line 45 | Line 46 | type
46   implementation
47  
48   uses
49 <  SysUtils, Data, Functions, ABSDecUtil, DB;
49 >  SysUtils, Data, Functions, ABSDecUtil, DB, DatLinks, StrUtils;
50  
51  
52   (*
# Line 55 | Line 56 | uses
56  
57  
58   constructor TAccess_OUP_ADB.Create(DBFilename: String; ConnectionID: Integer; var Msg: TStatusMessages);
58 var
59  i: Integer;
59   begin
60    Msg := SM_UnknownError;
61    if not FileExists(DBFilename) then
# Line 67 | Line 66 | begin
66    FFileName := DBFilename;
67  
68    FDatabase := TABSDatabase.Create(nil);
69 +  FDatabase.Exclusive := True;
70 +  FDatabase.MultiUser := False;
71    FDatabase.DatabaseName := 'OLDBcon' + IntToStr(ConnectionID);
72    FDatabase.DatabaseFileName := DBFilename;
73    FDatabase.Open;
74    FQuery := TABSQuery.Create(FDatabase);
75 +  FQuery.DisableControls;
76 +  FQuery.RequestLive := False;
77    FQuery.DatabaseName := 'OLDBcon' + IntToStr(ConnectionID);
78    FQuery.SQL.Text := 'SELECT [name],[value] FROM globals ORDER BY [name] ASC';
79    FQuery.Open;
# Line 87 | Line 90 | begin
90      end;
91      if FQuery.FieldByName('name').AsString = 'lvl' then
92        FLevelNumber := StrToInt(FQuery.FieldByName('value').AsString);
93 <    if FQuery.FieldByName('name').AsString = 'DataOS' then
93 >    if FQuery.FieldByName('name').AsString = 'os' then
94      begin
95        if FQuery.FieldByName('value').AsString = 'WIN' then
96          FDataOS := DOS_WIN
# Line 141 | Line 144 | begin
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;
147 <      Fdat_files[i].FileType := HexToLong(FQuery.FieldByName('contenttype').AsString);
147 >      Fdat_files[i].FileType := StrToInt('$'+FQuery.FieldByName('contenttype').AsString);
148        Fdat_files[i].DatAddr := 0;
149        Inc(i);
150        FQuery.Next;
# Line 193 | Line 196 | begin
196    FQuery.Close;
197   end;
198  
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
199  
200  
201   function TAccess_OUP_ADB.GetFileInfo(fileid: Integer): TFileInfo;
# Line 231 | Line 213 | end;
213  
214  
215  
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  
225   function TAccess_OUP_ADB.GetFilesList(ext: String; pattern: String;
226    NoEmptyFiles: Boolean; SortType: TSortType): TStrings;
# Line 271 | Line 261 | var
261  
262   begin
263    list := TStringList.Create;
264 <  list.Sorted := True;
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
269    begin
270      if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and
# Line 288 | Line 281 | begin
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(name + ';' + extension + ';' + id);
284 >          ST_ExtNameAsc, ST_ExtNameDesc: list.Add(extension + ';' + name + ';' + id);
285          end;
286        end;
287      end;
288    end;
289 <  Result := TStringList.Create;
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
294    begin
295      fields := TStringList.Create;
# Line 327 | Line 323 | function TAccess_OUP_ADB.GetExtensionsLi
323   var
324    i: Integer;
325   begin
326 <  Result := TStringList.Create;
326 >  if not Assigned(Result) then
327 >    Result := TStringList.Create;
328 >  if Result is TStringList then
329 >    TStringList(Result).Sorted := True;
330    for i := 0 to Length(Fdat_extensionsmap) - 1 do
331    begin
332      with Fdat_extensionsmap[i] do
# Line 440 | Line 439 | begin
439    end;
440   end;
441  
442 +
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  
485   function TAccess_OUP_ADB.GetRawList(FileID: Integer): TRawDataList;
486   var

Diff Legend

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