Resource

Resource Basics

Resource Name Filter with Sidecar File
Resource Version 1.01
Category Filter Script
Downloads 703
Release Date 7/13/2022 5:06:18 PM
 

Resource Details

Description This script allows you to filter a collection based on the existence of a sidecar file that matches a file mask.
Installation Instructions n.a.
Usage Instructions In the application, click the Filter button, then select From Repository and select this script.
Changes in this version Fix for possible "Count" exception
Special Requirements
 

Author Information

Author Name IDimager Support
 

Script

var
  AExtensionMasks: TTntStringList;
  AMasks: WideString;

function Initialize: Boolean;
begin
  // return false to cancel the filter operation

  AExtensionMasks := nil;

  result := False;
  AMasks := ReadFromRegistry('FilterWithSidecars', 'Extensions', '*.*');
  if AskInput('Filter Sidecar', 'Enter the file mask for the sidecar files that should be returned (multiple can be comma separated)', '', AMasks, False, nil) then
  begin
    if Trim(AMasks) = '' then
      AMasks := '*.*';

    WriteToRegistry('FilterWithSidecars', 'Extensions', AMasks);
    result := True;
  end;
end;

procedure Finalize;
begin
  AExtensionMasks.Free;
  AExtensionMasks := nil;
end;

function IsMatchingSidecar(AFileName: WideString): Boolean;
var
  i: Integer;
  AMask: WideString;
begin
  if AExtensionMasks = nil then
  begin
    AExtensionMasks := TTntStringList.Create;
    AExtensionMasks.CommaText := AMasks;
  end;

  result := False;
  for i := 0 to AExtensionMasks.Count - 1 do
  begin
    AMask := AExtensionMasks.Strings[i];
    if WideMatchesMask(AFileName, AMask) then
    begin
      result := True;
      break;
    end;
  end;
end;

function Filter(AItem: TImageItem): Boolean;
var
  AFiles: TTntStringList;
  AFile: WideString;
  i: Integer;
begin
  AItem.Fetch;

  result := False;

  AFiles := TTntStringList.Create;
  SidecarExtensions.EnumSidecarFilesFor(AItem.FileName, AFiles);
  for i := 0 to AFiles.Count - 1 do
  begin
    AFile := AFiles.Strings[i];
    if IsMatchingSidecar(AFile) then
    begin
      result := True;
      break;
    end;
  end;
  AFiles.Free;
end;