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

Comparing:
oup/rewrite/DataAccess/Access_OUP_ADB.pas (file contents), Revision 101 by alloc, Tue Feb 20 20:43:29 2007 UTC vs.
oup/current/DataAccess/Access_OUP_ADB.pas (file contents), Revision 119 by alloc, Fri Mar 23 00:58:41 2007 UTC

# Line 17 | Line 17 | type
17  
18      procedure UpdateListCache;
19  
20 +    function GetLinksToFile(FileID: Integer): TLinks;
21 +
22      function GetFileInfo(FileID: Integer): TFileInfo; override;
23      function GetFilesList(Ext: String; Pattern: String;
24        NoEmptyFiles: Boolean; SortType: TSortType): TStrings; override;
# Line 28 | 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 42 | Line 46 | type
46   implementation
47  
48   uses
49 <  SysUtils, Data, Functions, ABSDecUtil, DB;
49 >  SysUtils, Data, Functions, ABSDecUtil, DB, DatLinks;
50  
51  
52   (*
# Line 52 | Line 56 | uses
56  
57  
58   constructor TAccess_OUP_ADB.Create(DBFilename: String; ConnectionID: Integer; var Msg: TStatusMessages);
55 var
56  i: Integer;
59   begin
60    Msg := SM_UnknownError;
61    if not FileExists(DBFilename) then
# Line 102 | Line 104 | begin
104    Msg := SM_OK;
105    FBackend := DB_ADB;
106  
107 +  FConnectionID := ConnectionID;
108    FChangeRights := [CR_EditDat, CR_EditRaw, CR_ResizeDat, CR_ResizeRaw];
109  
110    UpdateListCache;
# Line 137 | Line 140 | begin
140        Fdat_files[i].Name := FQuery.FieldByName('name').AsString;
141        Fdat_files[i].Extension := FQuery.FieldByName('extension').AsString;
142        Fdat_files[i].Size := FQuery.FieldByName('size').AsInteger;
143 <      Fdat_files[i].FileType := HexToLong(FQuery.FieldByName('contenttype').AsString);
143 >      Fdat_files[i].FileType := StrToInt('$'+FQuery.FieldByName('contenttype').AsString);
144        Fdat_files[i].DatAddr := 0;
145        Inc(i);
146        FQuery.Next;
# Line 167 | Line 170 | begin
170   end;
171  
172  
173 +
174 + function TAccess_OUP_ADB.GetLinksToFile(FileID: Integer): TLinks;
175 + var
176 +  i: Integer;
177 + begin
178 +  SetLength(Result.ByName, 0);
179 +  FQuery.SQL.Text := 'SELECT src_link_offset, src_id FROM linkmap WHERE target_id = ' + IntToStr(FileID) + ' ORDER BY src_id ASC;';
180 +  FQuery.Open;
181 +  SetLength(Result.ByID, FQuery.RecordCount);
182 +  if FQuery.RecordCount > 0 then
183 +  begin
184 +    i := 0;
185 +    repeat
186 +      Result.ByID[i].SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger;
187 +      Result.ByID[i].Destination := FQuery.FieldByName('src_id').AsInteger;
188 +      Inc(i);
189 +      FQuery.Next;
190 +    until FQuery.EOF;
191 +  end;
192 +  FQuery.Close;
193 + end;
194 +
195 +
196 +
197   function TAccess_OUP_ADB.GetFileInfo(fileid: Integer): TFileInfo;
198   begin
199    if fileid = -1 then
# Line 212 | Line 239 | var
239        name := fields.Strings[2];
240        extension := fields.Strings[0];
241      end;
242 +    if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then
243 +    begin
244 +      id := fields.Strings[2];
245 +      name := fields.Strings[1];
246 +      extension := fields.Strings[0];
247 +    end;
248    end;
249  
250   begin
# Line 225 | Line 258 | begin
258      begin
259        if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then
260        begin
261 <        if AppSettings.FilenumbersAsHex then
229 <          id := IntToHex(Fdat_files[i].ID, 4)
230 <        else
231 <          id := FormatNumber(Fdat_files[i].ID, 5, '0');
261 >        id := FormatNumber(Fdat_files[i].ID, 5, '0');
262          name := Fdat_files[i].Name;
263          extension := Fdat_files[i].Extension;
264  
# Line 236 | Line 266 | begin
266            ST_IDAsc, ST_IDDesc:     list.Add(id + ';' + name + ';' + extension);
267            ST_NameAsc, ST_NameDesc: list.Add(name + ';' + id + ';' + extension);
268            ST_ExtAsc, ST_ExtDesc:   list.Add(extension + ';' + id + ';' + name);
269 +          ST_ExtNameAsc, ST_ExtNameDesc: list.Add(name + ';' + extension + ';' + id);
270          end;
271        end;
272      end;
273    end;
274 <  Result := TStringList.Create;
274 >  if not Assigned(Result) then
275 >    Result := TStringList.Create;
276    if list.Count > 0 then
277    begin
278      fields := TStringList.Create;
279 <    if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc] then
279 >    if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc, ST_ExtNameAsc] then
280        for i := 0 to list.Count - 1 do
281        begin
282          getfields;
# Line 274 | Line 306 | function TAccess_OUP_ADB.GetExtensionsLi
306   var
307    i: Integer;
308   begin
309 <  Result := TStringList.Create;
309 >  if not Assigned(Result) then
310 >    Result := TStringList.Create;
311 >  if Result is TStringList then
312 >    TStringList(Result).Sorted := True;
313    for i := 0 to Length(Fdat_extensionsmap) - 1 do
314    begin
315      with Fdat_extensionsmap[i] do
# Line 387 | Line 422 | begin
422    end;
423   end;
424  
425 +
426 +
427 + function TAccess_OUP_ADB.GetDatLink(FileID, DatOffset: Integer): TDatLink;
428 + begin
429 +  Result := DatLinksManager.GetDatLink(FConnectionID, FileID, DatOffset);
430 +  FQuery.SQL.Text := 'SELECT target_id FROM linkmap WHERE src_id = ' + IntToStr(FileID) + ' and src_link_offset = ' + IntToStr(DatOffset) + ';';
431 +  FQuery.Open;
432 +  if FQuery.RecordCount > 0 then
433 +    Result.DestID := FQuery.FieldByName('target_id').AsInteger;
434 +  FQuery.Close;
435 + end;
436 +
437 +
438 + function TAccess_OUP_ADB.GetDatLinks(FileID: Integer): TDatLinkList;
439 + var
440 +  i: Integer;
441 +  SrcOffset, DestID: Integer;
442 + begin
443 +  Result := DatLinksManager.GetDatLinks(FConnectionID, FileID);
444 +  if Length(Result) > 0 then
445 +  begin
446 +    FQuery.SQL.Text := 'SELECT src_link_offset, target_id FROM linkmap WHERE src_id = ' + IntToStr(FileID) + ' ORDER BY src_link_offset ASC;';
447 +    FQuery.Open;
448 +    if FQuery.RecordCount > 0 then
449 +    begin
450 +      repeat
451 +        SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger;
452 +        DestID := FQuery.FieldByName('target_id').AsInteger;
453 +        for i := 0 to High(Result) do
454 +          if Result[i].SrcOffset = SrcOffset then
455 +            Break;
456 +        if i < Length(Result) then
457 +          Result[i].DestID := DestID
458 +        else
459 +          Result[i].DestID := -1;
460 +        FQuery.Next;
461 +      until FQuery.EOF;
462 +    end;
463 +    FQuery.Close;
464 +  end;
465 + end;
466 +
467  
468   function TAccess_OUP_ADB.GetRawList(FileID: Integer): TRawDataList;
469   var

Diff Legend

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