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 135 by alloc, Wed Mar 28 17:57:12 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 64 | 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 102 | Line 108 | begin
108    Msg := SM_OK;
109    FBackend := DB_ADB;
110  
111 +  FConnectionID := ConnectionID;
112    FChangeRights := [CR_EditDat, CR_EditRaw, CR_ResizeDat, CR_ResizeRaw];
113  
114    UpdateListCache;
# Line 137 | 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 167 | Line 174 | begin
174   end;
175  
176  
177 +
178 + function TAccess_OUP_ADB.GetLinksToFile(FileID: Integer): TLinks;
179 + var
180 +  i: Integer;
181 + begin
182 +  SetLength(Result.ByName, 0);
183 +  FQuery.SQL.Text := 'SELECT src_link_offset, src_id FROM linkmap WHERE target_id = ' + IntToStr(FileID) + ' ORDER BY src_id ASC;';
184 +  FQuery.Open;
185 +  SetLength(Result.ByID, FQuery.RecordCount);
186 +  if FQuery.RecordCount > 0 then
187 +  begin
188 +    i := 0;
189 +    repeat
190 +      Result.ByID[i].SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger;
191 +      Result.ByID[i].Destination := FQuery.FieldByName('src_id').AsInteger;
192 +      Inc(i);
193 +      FQuery.Next;
194 +    until FQuery.EOF;
195 +  end;
196 +  FQuery.Close;
197 + end;
198 +
199 +
200 +
201   function TAccess_OUP_ADB.GetFileInfo(fileid: Integer): TFileInfo;
202   begin
203    if fileid = -1 then
# Line 212 | Line 243 | var
243        name := fields.Strings[2];
244        extension := fields.Strings[0];
245      end;
246 +    if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then
247 +    begin
248 +      id := fields.Strings[2];
249 +      name := fields.Strings[1];
250 +      extension := fields.Strings[0];
251 +    end;
252    end;
253  
254   begin
# Line 225 | Line 262 | begin
262      begin
263        if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then
264        begin
265 <        if AppSettings.FilenumbersAsHex then
229 <          id := IntToHex(Fdat_files[i].ID, 4)
230 <        else
231 <          id := FormatNumber(Fdat_files[i].ID, 5, '0');
265 >        id := FormatNumber(Fdat_files[i].ID, 5, '0');
266          name := Fdat_files[i].Name;
267          extension := Fdat_files[i].Extension;
268  
# Line 236 | Line 270 | begin
270            ST_IDAsc, ST_IDDesc:     list.Add(id + ';' + name + ';' + extension);
271            ST_NameAsc, ST_NameDesc: list.Add(name + ';' + id + ';' + extension);
272            ST_ExtAsc, ST_ExtDesc:   list.Add(extension + ';' + id + ';' + name);
273 +          ST_ExtNameAsc, ST_ExtNameDesc: list.Add(name + ';' + extension + ';' + id);
274          end;
275        end;
276      end;
277    end;
278 <  Result := TStringList.Create;
278 >  if not Assigned(Result) then
279 >    Result := TStringList.Create;
280    if list.Count > 0 then
281    begin
282      fields := TStringList.Create;
283 <    if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc] then
283 >    if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc, ST_ExtNameAsc] then
284        for i := 0 to list.Count - 1 do
285        begin
286          getfields;
# Line 274 | Line 310 | function TAccess_OUP_ADB.GetExtensionsLi
310   var
311    i: Integer;
312   begin
313 <  Result := TStringList.Create;
313 >  if not Assigned(Result) then
314 >    Result := TStringList.Create;
315 >  if Result is TStringList then
316 >    TStringList(Result).Sorted := True;
317    for i := 0 to Length(Fdat_extensionsmap) - 1 do
318    begin
319      with Fdat_extensionsmap[i] do
# Line 387 | Line 426 | begin
426    end;
427   end;
428  
429 +
430 +
431 + function TAccess_OUP_ADB.GetDatLink(FileID, DatOffset: Integer): TDatLink;
432 + begin
433 +  Result := DatLinksManager.GetDatLink(FConnectionID, FileID, DatOffset);
434 +  FQuery.SQL.Text := 'SELECT target_id FROM linkmap WHERE src_id = ' + IntToStr(FileID) + ' and src_link_offset = ' + IntToStr(DatOffset) + ';';
435 +  FQuery.Open;
436 +  if FQuery.RecordCount > 0 then
437 +    Result.DestID := FQuery.FieldByName('target_id').AsInteger;
438 +  FQuery.Close;
439 + end;
440 +
441 +
442 + function TAccess_OUP_ADB.GetDatLinks(FileID: Integer): TDatLinkList;
443 + var
444 +  i: Integer;
445 +  SrcOffset, DestID: Integer;
446 + begin
447 +  Result := DatLinksManager.GetDatLinks(FConnectionID, FileID);
448 +  if Length(Result) > 0 then
449 +  begin
450 +    FQuery.SQL.Text := 'SELECT src_link_offset, target_id FROM linkmap WHERE src_id = ' + IntToStr(FileID) + ' ORDER BY src_link_offset ASC;';
451 +    FQuery.Open;
452 +    if FQuery.RecordCount > 0 then
453 +    begin
454 +      repeat
455 +        SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger;
456 +        DestID := FQuery.FieldByName('target_id').AsInteger;
457 +        for i := 0 to High(Result) do
458 +          if Result[i].SrcOffset = SrcOffset then
459 +            Break;
460 +        if i < Length(Result) then
461 +          Result[i].DestID := DestID
462 +        else
463 +          Result[i].DestID := -1;
464 +        FQuery.Next;
465 +      until FQuery.EOF;
466 +    end;
467 +    FQuery.Close;
468 +  end;
469 + end;
470 +
471  
472   function TAccess_OUP_ADB.GetRawList(FileID: Integer): TRawDataList;
473   var

Diff Legend

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