| 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; |
| 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 |
|
|
| 46 |
|
implementation |
| 47 |
|
|
| 48 |
|
uses |
| 49 |
< |
SysUtils, Data, Functions, ABSDecUtil, DB; |
| 49 |
> |
SysUtils, Data, Functions, ABSDecUtil, DB, DatLinks, StrUtils; |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
(* |
| 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 |
| 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; |
| 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; |
| 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; |
| 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 |
| 213 |
|
|
| 214 |
|
|
| 215 |
|
|
| 216 |
+ |
function CompareItems(List: TStringList; I1, I2: Integer): Integer; |
| 217 |
+ |
var |
| 218 |
+ |
fin: Boolean; |
| 219 |
+ |
pos: Integer; |
| 220 |
+ |
s1, s2: String; |
| 221 |
+ |
begin |
| 222 |
+ |
fin := False; |
| 223 |
+ |
s1 := MidStr(List[I1], 1, PosEx(';', List[I1], 6) - 1); |
| 224 |
+ |
s2 := MidStr(List[I2], 1, PosEx(';', List[I2], 6) - 1); |
| 225 |
+ |
pos := 1; |
| 226 |
+ |
Result := 0; |
| 227 |
+ |
repeat |
| 228 |
+ |
if Ord(s1[pos]) < Ord(s2[pos]) then |
| 229 |
+ |
begin |
| 230 |
+ |
Result := -1; |
| 231 |
+ |
fin := True; |
| 232 |
+ |
end |
| 233 |
+ |
else if Ord(s1[pos]) > Ord(s2[pos]) then |
| 234 |
+ |
begin |
| 235 |
+ |
Result := 1; |
| 236 |
+ |
fin := True; |
| 237 |
+ |
end; |
| 238 |
+ |
Inc(pos); |
| 239 |
+ |
until fin or (pos > Length(s1)) or (pos > Length(s2)); |
| 240 |
+ |
|
| 241 |
+ |
if not fin then |
| 242 |
+ |
begin |
| 243 |
+ |
if pos > Length(s1) then |
| 244 |
+ |
Result := -1 |
| 245 |
+ |
else |
| 246 |
+ |
Result := 1; |
| 247 |
+ |
end; |
| 248 |
+ |
end; |
| 249 |
|
|
| 250 |
|
function TAccess_OUP_ADB.GetFilesList(ext: String; pattern: String; |
| 251 |
|
NoEmptyFiles: Boolean; SortType: TSortType): TStrings; |
| 276 |
|
name := fields.Strings[2]; |
| 277 |
|
extension := fields.Strings[0]; |
| 278 |
|
end; |
| 279 |
+ |
if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then |
| 280 |
+ |
begin |
| 281 |
+ |
id := fields.Strings[2]; |
| 282 |
+ |
name := fields.Strings[1]; |
| 283 |
+ |
extension := fields.Strings[0]; |
| 284 |
+ |
end; |
| 285 |
|
end; |
| 286 |
|
|
| 287 |
|
begin |
| 288 |
|
list := TStringList.Create; |
| 289 |
< |
list.Sorted := True; |
| 289 |
> |
if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then |
| 290 |
> |
list.Sorted := False |
| 291 |
> |
else |
| 292 |
> |
list.Sorted := True; |
| 293 |
|
for i := 0 to GetFileCount - 1 do |
| 294 |
|
begin |
| 295 |
|
if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and |
| 298 |
|
begin |
| 299 |
|
if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then |
| 300 |
|
begin |
| 301 |
< |
if AppSettings.FilenumbersAsHex then |
| 229 |
< |
id := IntToHex(Fdat_files[i].ID, 4) |
| 230 |
< |
else |
| 231 |
< |
id := FormatNumber(Fdat_files[i].ID, 5, '0'); |
| 301 |
> |
id := FormatNumber(Fdat_files[i].ID, 5, '0'); |
| 302 |
|
name := Fdat_files[i].Name; |
| 303 |
|
extension := Fdat_files[i].Extension; |
| 304 |
|
|
| 306 |
|
ST_IDAsc, ST_IDDesc: list.Add(id + ';' + name + ';' + extension); |
| 307 |
|
ST_NameAsc, ST_NameDesc: list.Add(name + ';' + id + ';' + extension); |
| 308 |
|
ST_ExtAsc, ST_ExtDesc: list.Add(extension + ';' + id + ';' + name); |
| 309 |
+ |
ST_ExtNameAsc, ST_ExtNameDesc: list.Add(extension + ';' + name + ';' + id); |
| 310 |
|
end; |
| 311 |
|
end; |
| 312 |
|
end; |
| 313 |
|
end; |
| 314 |
< |
Result := TStringList.Create; |
| 314 |
> |
if SortType in [ST_ExtNameAsc, ST_ExtNameDesc] then |
| 315 |
> |
list.CustomSort(CompareItems); |
| 316 |
> |
if not Assigned(Result) then |
| 317 |
> |
Result := TStringList.Create; |
| 318 |
|
if list.Count > 0 then |
| 319 |
|
begin |
| 320 |
|
fields := TStringList.Create; |
| 321 |
< |
if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc] then |
| 321 |
> |
if SortType in [ST_IDAsc, ST_NameAsc, ST_ExtAsc, ST_ExtNameAsc] then |
| 322 |
|
for i := 0 to list.Count - 1 do |
| 323 |
|
begin |
| 324 |
|
getfields; |
| 348 |
|
var |
| 349 |
|
i: Integer; |
| 350 |
|
begin |
| 351 |
< |
Result := TStringList.Create; |
| 351 |
> |
if not Assigned(Result) then |
| 352 |
> |
Result := TStringList.Create; |
| 353 |
> |
if Result is TStringList then |
| 354 |
> |
TStringList(Result).Sorted := True; |
| 355 |
|
for i := 0 to Length(Fdat_extensionsmap) - 1 do |
| 356 |
|
begin |
| 357 |
|
with Fdat_extensionsmap[i] do |
| 464 |
|
end; |
| 465 |
|
end; |
| 466 |
|
|
| 467 |
+ |
|
| 468 |
+ |
|
| 469 |
+ |
function TAccess_OUP_ADB.GetDatLink(FileID, DatOffset: Integer): TDatLink; |
| 470 |
+ |
begin |
| 471 |
+ |
Result := DatLinksManager.GetDatLink(FConnectionID, FileID, DatOffset); |
| 472 |
+ |
FQuery.SQL.Text := 'SELECT target_id FROM linkmap WHERE src_id = ' + IntToStr(FileID) + ' and src_link_offset = ' + IntToStr(DatOffset) + ';'; |
| 473 |
+ |
FQuery.Open; |
| 474 |
+ |
if FQuery.RecordCount > 0 then |
| 475 |
+ |
Result.DestID := FQuery.FieldByName('target_id').AsInteger; |
| 476 |
+ |
FQuery.Close; |
| 477 |
+ |
end; |
| 478 |
+ |
|
| 479 |
+ |
|
| 480 |
+ |
function TAccess_OUP_ADB.GetDatLinks(FileID: Integer): TDatLinkList; |
| 481 |
+ |
var |
| 482 |
+ |
i: Integer; |
| 483 |
+ |
SrcOffset, DestID: Integer; |
| 484 |
+ |
begin |
| 485 |
+ |
Result := DatLinksManager.GetDatLinks(FConnectionID, FileID); |
| 486 |
+ |
if Length(Result) > 0 then |
| 487 |
+ |
begin |
| 488 |
+ |
FQuery.SQL.Text := 'SELECT src_link_offset, target_id FROM linkmap WHERE src_id = ' + IntToStr(FileID) + ' ORDER BY src_link_offset ASC;'; |
| 489 |
+ |
FQuery.Open; |
| 490 |
+ |
if FQuery.RecordCount > 0 then |
| 491 |
+ |
begin |
| 492 |
+ |
repeat |
| 493 |
+ |
SrcOffset := FQuery.FieldByName('src_link_offset').AsInteger; |
| 494 |
+ |
DestID := FQuery.FieldByName('target_id').AsInteger; |
| 495 |
+ |
for i := 0 to High(Result) do |
| 496 |
+ |
if Result[i].SrcOffset = SrcOffset then |
| 497 |
+ |
Break; |
| 498 |
+ |
if i < Length(Result) then |
| 499 |
+ |
Result[i].DestID := DestID |
| 500 |
+ |
else |
| 501 |
+ |
Result[i].DestID := -1; |
| 502 |
+ |
FQuery.Next; |
| 503 |
+ |
until FQuery.EOF; |
| 504 |
+ |
end; |
| 505 |
+ |
FQuery.Close; |
| 506 |
+ |
end; |
| 507 |
+ |
end; |
| 508 |
+ |
|
| 509 |
|
|
| 510 |
|
function TAccess_OUP_ADB.GetRawList(FileID: Integer): TRawDataList; |
| 511 |
|
var |