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 116 by alloc, Mon Feb 26 22:57:02 2007 UTC

# Line 17 | Line 17 | type
17  
18      procedure UpdateListCache;
19  
20 +    function GetLinksToFile(FileID: Integer): TLinks;
21 +    function GetLinksFromFile(FileID: Integer): TLinks;
22 +
23      function GetFileInfo(FileID: Integer): TFileInfo; override;
24      function GetFilesList(Ext: String; Pattern: String;
25        NoEmptyFiles: Boolean; SortType: TSortType): TStrings; override;
# Line 28 | Line 31 | type
31      procedure LoadDatFilePart(FileID, Offset, Size: Integer; var Target: TStream); overload; override;
32      procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TStream); overload; override;
33  
34 +    function GetDatLinks(FileID: Integer): TDatLinkList; override;
35 +    function GetDatLink(FileID, DatOffset: Integer): TDatLink; override;
36      function GetRawList(FileID: Integer): TRawDataList; override;
37      function GetRawInfo(FileID, DatOffset: Integer): TRawDataInfo; override;
38  
# Line 42 | Line 47 | type
47   implementation
48  
49   uses
50 <  SysUtils, Data, Functions, ABSDecUtil, DB;
50 >  SysUtils, Data, Functions, ABSDecUtil, DB, DatLinks;
51  
52  
53   (*
# Line 52 | Line 57 | uses
57  
58  
59   constructor TAccess_OUP_ADB.Create(DBFilename: String; ConnectionID: Integer; var Msg: TStatusMessages);
55 var
56  i: Integer;
60   begin
61    Msg := SM_UnknownError;
62    if not FileExists(DBFilename) then
# Line 102 | Line 105 | begin
105    Msg := SM_OK;
106    FBackend := DB_ADB;
107  
108 +  FConnectionID := ConnectionID;
109    FChangeRights := [CR_EditDat, CR_EditRaw, CR_ResizeDat, CR_ResizeRaw];
110  
111    UpdateListCache;
# Line 137 | Line 141 | begin
141        Fdat_files[i].Name := FQuery.FieldByName('name').AsString;
142        Fdat_files[i].Extension := FQuery.FieldByName('extension').AsString;
143        Fdat_files[i].Size := FQuery.FieldByName('size').AsInteger;
144 <      Fdat_files[i].FileType := HexToLong(FQuery.FieldByName('contenttype').AsString);
144 >      Fdat_files[i].FileType := StrToInt('$'+FQuery.FieldByName('contenttype').AsString);
145        Fdat_files[i].DatAddr := 0;
146        Inc(i);
147        FQuery.Next;
# Line 167 | Line 171 | begin
171   end;
172  
173  
174 +
175 + function TAccess_OUP_ADB.GetLinksToFile(FileID: Integer): TLinks;
176 + var
177 +  i: Integer;
178 + begin
179 +  SetLength(Result.ByName, 0);
180 +  FQuery.SQL.Text := 'SELECT src_link_offset, src_id FROM linkmap WHERE target_id = ' + IntToStr(FileID) + ' ORDER BY src_id ASC;';
181 +  FQuery.Open;
182 +  SetLength(Result.ByID, FQuery.RecordCount);
183 +  if FQuery.RecordCount > 0 then
184 +  begin
185 +    i := 0;
186 +    repeat
187 +      Result.ByID[i].SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger;
188 +      Result.ByID[i].Destination := FQuery.FieldByName('src_id').AsInteger;
189 +      Inc(i);
190 +      FQuery.Next;
191 +    until FQuery.EOF;
192 +  end;
193 +  FQuery.Close;
194 + end;
195 +
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 +
217 +
218 +
219   function TAccess_OUP_ADB.GetFileInfo(fileid: Integer): TFileInfo;
220   begin
221    if fileid = -1 then
# Line 212 | Line 261 | var
261        name := fields.Strings[2];
262        extension := fields.Strings[0];
263      end;
264 +    if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then
265 +    begin
266 +      id := fields.Strings[2];
267 +      name := fields.Strings[1];
268 +      extension := fields.Strings[0];
269 +    end;
270    end;
271  
272   begin
# Line 225 | Line 280 | begin
280      begin
281        if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then
282        begin
283 <        if AppSettings.FilenumbersAsHex then
229 <          id := IntToHex(Fdat_files[i].ID, 4)
230 <        else
231 <          id := FormatNumber(Fdat_files[i].ID, 5, '0');
283 >        id := FormatNumber(Fdat_files[i].ID, 5, '0');
284          name := Fdat_files[i].Name;
285          extension := Fdat_files[i].Extension;
286  
# Line 236 | Line 288 | begin
288            ST_IDAsc, ST_IDDesc:     list.Add(id + ';' + name + ';' + extension);
289            ST_NameAsc, ST_NameDesc: list.Add(name + ';' + id + ';' + extension);
290            ST_ExtAsc, ST_ExtDesc:   list.Add(extension + ';' + id + ';' + name);
291 +          ST_ExtNameAsc, ST_ExtNameDesc: list.Add(name + ';' + extension + ';' + id);
292          end;
293        end;
294      end;
295    end;
296 <  Result := TStringList.Create;
296 >  if not Assigned(Result) then
297 >    Result := TStringList.Create;
298    if list.Count > 0 then
299    begin
300      fields := TStringList.Create;
301 <    if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc] then
301 >    if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc, ST_ExtNameAsc] then
302        for i := 0 to list.Count - 1 do
303        begin
304          getfields;
# Line 274 | Line 328 | function TAccess_OUP_ADB.GetExtensionsLi
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
# Line 387 | Line 444 | begin
444    end;
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

Diff Legend

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