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 106 by alloc, Wed Feb 21 03:09:30 2007 UTC vs.
oup/current/DataAccess/Access_OUP_ADB.pas (file contents), Revision 157 by alloc, Sun Apr 1 23:47:18 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 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  
234
216   function TAccess_OUP_ADB.GetFilesList(ext: String; pattern: String;
217    NoEmptyFiles: Boolean; SortType: TSortType): TStrings;
218   var
# Line 261 | Line 242 | var
242        name := fields.Strings[2];
243        extension := fields.Strings[0];
244      end;
245 +    if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then
246 +    begin
247 +      id := fields.Strings[2];
248 +      name := fields.Strings[1];
249 +      extension := fields.Strings[0];
250 +    end;
251    end;
252  
253   begin
254 <  list := TStringList.Create;
255 <  list.Sorted := True;
256 <  for i := 0 to GetFileCount - 1 do
257 <  begin
258 <    if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and
272 <      ((Length(pattern) = 0) or
273 <      (Pos(UpperCase(pattern), UpperCase(Fdat_files[i].Name)) > 0)) then
254 >  if not (SortType in [ST_ExtNameAsc, ST_ExtNameDesc]) then
255 >  begin
256 >    list := TStringList.Create;
257 >    list.Sorted := True;
258 >    for i := 0 to GetFileCount - 1 do
259      begin
260 <      if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then
260 >      if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and
261 >        ((Length(pattern) = 0) or
262 >        (Pos(UpperCase(pattern), UpperCase(Fdat_files[i].Name)) > 0)) then
263        begin
264 <        if AppSettings.FilenumbersAsHex then
265 <          id := IntToHex(Fdat_files[i].ID, 4)
279 <        else
264 >        if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then
265 >        begin
266            id := FormatNumber(Fdat_files[i].ID, 5, '0');
267 <        name := Fdat_files[i].Name;
268 <        extension := Fdat_files[i].Extension;
267 >          name := Fdat_files[i].Name;
268 >          extension := Fdat_files[i].Extension;
269  
270 <        case SortType of
271 <          ST_IDAsc, ST_IDDesc:     list.Add(id + ';' + name + ';' + extension);
272 <          ST_NameAsc, ST_NameDesc: list.Add(name + ';' + id + ';' + extension);
273 <          ST_ExtAsc, ST_ExtDesc:   list.Add(extension + ';' + id + ';' + name);
270 >          case SortType of
271 >            ST_IDAsc, ST_IDDesc:     list.Add(id + ';' + name + ';' + extension);
272 >            ST_NameAsc, ST_NameDesc: list.Add(name + ';' + id + ';' + extension);
273 >            ST_ExtAsc, ST_ExtDesc:   list.Add(extension + ';' + id + ';' + name);
274 >            ST_ExtNameAsc, ST_ExtNameDesc: list.Add(extension + ';' + name + ';' + id);
275 >          end;
276          end;
277        end;
278      end;
279 <  end;
280 <  Result := TStringList.Create;
281 <  if list.Count > 0 then
279 >    if not Assigned(Result) then
280 >      Result := TStringList.Create;
281 >    if list.Count > 0 then
282 >    begin
283 >      fields := TStringList.Create;
284 >      if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc, ST_ExtNameAsc] then
285 >        for i := 0 to list.Count - 1 do
286 >        begin
287 >          getfields;
288 >          Result.Add(id + '-' + name + '.' + extension);
289 >        end
290 >      else
291 >        for i := list.Count - 1 downto 0 do
292 >        begin
293 >          getfields;
294 >          Result.Add(id + '-' + name + '.' + extension);
295 >        end;
296 >      fields.Free;
297 >    end;
298 >    list.Free;
299 >  end
300 >  else
301    begin
302 <    fields := TStringList.Create;
303 <    if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc] then
304 <      for i := 0 to list.Count - 1 do
305 <      begin
306 <        getfields;
307 <        Result.Add(id + '-' + name + '.' + extension);
308 <      end
309 <    else
310 <      for i := list.Count - 1 downto 0 do
311 <      begin
312 <        getfields;
313 <        Result.Add(id + '-' + name + '.' + extension);
314 <      end;
315 <    fields.Free;
302 >    FQuery.SQL.Text := 'SELECT id, name, extension FROM datfiles ' +
303 >        'WHERE Length(name) > 0 ORDER BY extension ASC, name ASC;';
304 >    FQuery.Open;
305 >    if not Assigned(Result) then
306 >      Result := TStringList.Create;
307 >    if FQuery.RecordCount > 0 then
308 >    begin
309 >      FQuery.First;
310 >      repeat
311 >        name := FormatNumber(FQuery.FieldByName('id').AsInteger, 5, '0') +
312 >              '-' + FQuery.FieldByName('name').AsString + '.' +
313 >              FQuery.FieldByName('extension').AsString;
314 >        if SortType = ST_ExtNameAsc then
315 >          Result.Add(name)
316 >        else
317 >          Result.Insert(0, name);
318 >        FQuery.Next;
319 >      until FQuery.EOF;
320 >    end;
321 >    FQuery.Close;
322    end;
310  list.Free;
323   end;
324  
325  
# Line 323 | Line 335 | function TAccess_OUP_ADB.GetExtensionsLi
335   var
336    i: Integer;
337   begin
338 <  Result := TStringList.Create;
338 >  if not Assigned(Result) then
339 >    Result := TStringList.Create;
340 >  if Result is TStringList then
341 >    TStringList(Result).Sorted := True;
342    for i := 0 to Length(Fdat_extensionsmap) - 1 do
343    begin
344      with Fdat_extensionsmap[i] do
# Line 436 | Line 451 | begin
451    end;
452   end;
453  
454 +
455 +
456 + function TAccess_OUP_ADB.GetDatLink(FileID, DatOffset: Integer): TDatLink;
457 + begin
458 +  Result := DatLinksManager.GetDatLink(FConnectionID, FileID, DatOffset);
459 +  FQuery.SQL.Text := 'SELECT target_id FROM linkmap WHERE src_id = ' + IntToStr(FileID) + ' and src_link_offset = ' + IntToStr(DatOffset) + ';';
460 +  FQuery.Open;
461 +  if FQuery.RecordCount > 0 then
462 +    Result.DestID := FQuery.FieldByName('target_id').AsInteger;
463 +  FQuery.Close;
464 + end;
465 +
466 +
467 + function TAccess_OUP_ADB.GetDatLinks(FileID: Integer): TDatLinkList;
468 + var
469 +  i: Integer;
470 +  SrcOffset, DestID: Integer;
471 + begin
472 +  Result := DatLinksManager.GetDatLinks(FConnectionID, FileID);
473 +  if Length(Result) > 0 then
474 +  begin
475 +    FQuery.SQL.Text := 'SELECT src_link_offset, target_id FROM linkmap WHERE src_id = ' + IntToStr(FileID) + ' ORDER BY src_link_offset ASC;';
476 +    FQuery.Open;
477 +    if FQuery.RecordCount > 0 then
478 +    begin
479 +      repeat
480 +        SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger;
481 +        DestID := FQuery.FieldByName('target_id').AsInteger;
482 +        for i := 0 to High(Result) do
483 +          if Result[i].SrcOffset = SrcOffset then
484 +            Break;
485 +        if i < Length(Result) then
486 +          Result[i].DestID := DestID
487 +        else
488 +          Result[i].DestID := -1;
489 +        FQuery.Next;
490 +      until FQuery.EOF;
491 +    end;
492 +    FQuery.Close;
493 +  end;
494 + end;
495 +
496  
497   function TAccess_OUP_ADB.GetRawList(FileID: Integer): TRawDataList;
498   var

Diff Legend

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