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 229 by alloc, Wed Jun 20 10:57:51 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, StrUtils;
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 84 | 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 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;
115 +
116 +  inherited;
117   end;
118  
119  
# Line 137 | Line 146 | begin
146        Fdat_files[i].Name := FQuery.FieldByName('name').AsString;
147        Fdat_files[i].Extension := FQuery.FieldByName('extension').AsString;
148        Fdat_files[i].Size := FQuery.FieldByName('size').AsInteger;
149 <      Fdat_files[i].FileType := HexToLong(FQuery.FieldByName('contenttype').AsString);
149 >      Fdat_files[i].FileType := StrToInt('$'+FQuery.FieldByName('contenttype').AsString);
150        Fdat_files[i].DatAddr := 0;
151        Inc(i);
152        FQuery.Next;
# Line 167 | Line 176 | begin
176   end;
177  
178  
179 +
180 + function TAccess_OUP_ADB.GetLinksToFile(FileID: Integer): TLinks;
181 + var
182 +  i: Integer;
183 + begin
184 +  SetLength(Result.ByName, 0);
185 +  FQuery.SQL.Text := 'SELECT src_link_offset, src_id FROM linkmap WHERE target_id = ' + IntToStr(FileID) + ' ORDER BY src_id ASC;';
186 +  FQuery.Open;
187 +  SetLength(Result.ByID, FQuery.RecordCount);
188 +  if FQuery.RecordCount > 0 then
189 +  begin
190 +    i := 0;
191 +    repeat
192 +      Result.ByID[i].SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger;
193 +      Result.ByID[i].Destination := FQuery.FieldByName('src_id').AsInteger;
194 +      Inc(i);
195 +      FQuery.Next;
196 +    until FQuery.EOF;
197 +  end;
198 +  FQuery.Close;
199 + end;
200 +
201 +
202 +
203   function TAccess_OUP_ADB.GetFileInfo(fileid: Integer): TFileInfo;
204   begin
205    if fileid = -1 then
# Line 182 | Line 215 | end;
215  
216  
217  
218 +  function CompareItems(List: TStringList; I1, I2: Integer): Integer;
219 +  var
220 +    s1, s2: String;
221 +  begin
222 +    s1 := MidStr(List[I1], 1, PosEx(';', List[I1], 6) - 1);
223 +    s2 := MidStr(List[I2], 1, PosEx(';', List[I2], 6) - 1);
224 +    Result := CompareStr(s1, s2);
225 +  end;
226  
227   function TAccess_OUP_ADB.GetFilesList(ext: String; pattern: String;
228    NoEmptyFiles: Boolean; SortType: TSortType): TStrings;
# Line 212 | Line 253 | var
253        name := fields.Strings[2];
254        extension := fields.Strings[0];
255      end;
256 +    if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then
257 +    begin
258 +      id := fields.Strings[2];
259 +      name := fields.Strings[1];
260 +      extension := fields.Strings[0];
261 +    end;
262    end;
263  
264   begin
265    list := TStringList.Create;
266 <  list.Sorted := True;
266 >  if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then
267 >    list.Sorted := False
268 >  else
269 >    list.Sorted := True;
270    for i := 0 to GetFileCount - 1 do
271    begin
272      if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and
# Line 225 | Line 275 | begin
275      begin
276        if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then
277        begin
278 <        if AppSettings.FilenumbersAsHex then
229 <          id := IntToHex(Fdat_files[i].ID, 4)
230 <        else
231 <          id := FormatNumber(Fdat_files[i].ID, 5, '0');
278 >        id := FormatNumber(Fdat_files[i].ID, 5, '0');
279          name := Fdat_files[i].Name;
280          extension := Fdat_files[i].Extension;
281  
# Line 236 | Line 283 | begin
283            ST_IDAsc, ST_IDDesc:     list.Add(id + ';' + name + ';' + extension);
284            ST_NameAsc, ST_NameDesc: list.Add(name + ';' + id + ';' + extension);
285            ST_ExtAsc, ST_ExtDesc:   list.Add(extension + ';' + id + ';' + name);
286 +          ST_ExtNameAsc, ST_ExtNameDesc: list.Add(extension + ';' + name + ';' + id);
287          end;
288        end;
289      end;
290    end;
291 <  Result := TStringList.Create;
291 >  if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then
292 >    list.CustomSort(CompareItems);
293 >  if not Assigned(Result) then
294 >    Result := TStringList.Create;
295    if list.Count > 0 then
296    begin
297      fields := TStringList.Create;
298 <    if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc] then
298 >    if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc, ST_ExtNameAsc] then
299        for i := 0 to list.Count - 1 do
300        begin
301          getfields;
# Line 274 | Line 325 | function TAccess_OUP_ADB.GetExtensionsLi
325   var
326    i: Integer;
327   begin
328 <  Result := TStringList.Create;
328 >  if not Assigned(Result) then
329 >    Result := TStringList.Create;
330 >  if Result is TStringList then
331 >    TStringList(Result).Sorted := True;
332    for i := 0 to Length(Fdat_extensionsmap) - 1 do
333    begin
334      with Fdat_extensionsmap[i] do
# Line 387 | Line 441 | begin
441    end;
442   end;
443  
444 +
445 +
446 + function TAccess_OUP_ADB.GetDatLink(FileID, DatOffset: Integer): TDatLink;
447 + begin
448 +  Result := DatLinksManager.GetDatLink(FConnectionID, FileID, DatOffset);
449 +  FQuery.SQL.Text := 'SELECT target_id FROM linkmap WHERE src_id = ' + IntToStr(FileID) + ' and src_link_offset = ' + IntToStr(DatOffset) + ';';
450 +  FQuery.Open;
451 +  if FQuery.RecordCount > 0 then
452 +    Result.DestID := FQuery.FieldByName('target_id').AsInteger;
453 +  FQuery.Close;
454 + end;
455 +
456 +
457 + function TAccess_OUP_ADB.GetDatLinks(FileID: Integer): TDatLinkList;
458 + var
459 +  i: Integer;
460 +  SrcOffset, DestID: Integer;
461 + begin
462 +  Result := DatLinksManager.GetDatLinks(FConnectionID, FileID);
463 +  if Length(Result) > 0 then
464 +  begin
465 +    FQuery.SQL.Text := 'SELECT src_link_offset, target_id FROM linkmap WHERE src_id = ' + IntToStr(FileID) + ' ORDER BY src_link_offset ASC;';
466 +    FQuery.Open;
467 +    if FQuery.RecordCount > 0 then
468 +    begin
469 +      repeat
470 +        SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger;
471 +        DestID := FQuery.FieldByName('target_id').AsInteger;
472 +        for i := 0 to High(Result) do
473 +          if Result[i].SrcOffset = SrcOffset then
474 +            Break;
475 +        if i < Length(Result) then
476 +          Result[i].DestID := DestID
477 +        else
478 +          Result[i].DestID := -1;
479 +        FQuery.Next;
480 +      until FQuery.EOF;
481 +    end;
482 +    FQuery.Close;
483 +  end;
484 + end;
485 +
486  
487   function TAccess_OUP_ADB.GetRawList(FileID: Integer): TRawDataList;
488   var

Diff Legend

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