//
// Example location script for 2BrightSparks SyncBackPro: Photos by Date.
//
// SBLang=Pascal
//
// http://www.2BrightSparks.com/
// November 2026
//
// Photos by Date shows the photos (and videos) in a folder, and all its
// sub-folders, rearranged into folders by the date each one was taken:
//
//   \2024\06\IMG_1234.jpg
//   \2024\07\DSC_0001.NEF
//
// It is read-only: the photos themselves are not moved or changed. Copy FROM
// it to another folder and you have a photo organiser: every photo, sorted by
// year and month, and kept up to date as you add more.
//
// The date taken comes from the photo's Exif data (JPEG, TIFF, HEIC and the
// raw files of most cameras) or, for a video, the date it was recorded. A
// photo with no date taken goes by the date the file was last changed, or in
// a "No date taken" folder if you choose.
//
// Two photos can end up in the same folder with the same name (e.g. two
// cameras that both made IMG_0001.jpg in June). The one taken first keeps its
// name and the others get (2), (3) and so on: IMG_0001 (2).jpg.
//
// Using it
// --------
// Make a new Backup profile that copies FROM Photos by Date, with the path \,
// TO a folder such as D:\Photos by Date\. A location script is always the
// destination of a profile, so SyncBack sets it up as "destination to source"
// for you. Use Backup rather than Mirror if you want to keep photos you have
// since deleted.
//
// Settings
// --------
// On the Photos by Date page of the profile setup:
//
//   Folder          The folder with your photos (required)
//   Folders         Year\Month (default), Year\Date or Year\Month\Day
//   Videos          Include videos (default on)
//   No date taken   Put photos without a date taken in a "No date taken"
//                   folder (default off: they go by the file's date)
//
// The date of each photo is remembered in
// %LOCALAPPDATA%\SyncBack Photos by Date\ so a photo is only read once.
//
// Insider Access
// --------------
// This script needs SyncBackPro V12 with Insider Access. It uses these
// Insider Access functions (they will be in every SyncBackPro V13):
//
//   SBSystem.GetDateTaken   To read the date a photo was taken
//   SBSystem.FindFiles      To find the photos
//   SBSystem.HashString     To name its index files
//
var
  gFSO, gSource, gIndex, gLayout, gVideos, gNoDateFolder, gMade,
  gOutDirs, gOut, gUsed;

const
  READ_ONLY = 'Photos by Date is read-only';
  NO_DATE = 'No date taken';
  PHOTO_MASKS = '*.jpg;*.jpeg;*.jpe;*.jfif;*.heic;*.heif;*.png;*.tif;*.tiff;*.webp;*.gif;*.bmp;*.dng;*.cr2;*.cr3;*.crw;*.nef;*.nrw;*.arw;*.srf;*.sr2;*.orf;*.rw2;*.raf;*.pef;*.srw;*.x3f';
  VIDEO_MASKS = '*.mp4;*.mov;*.m4v;*.avi;*.mts;*.m2ts;*.3gp;*.mkv;*.wmv';

//
// This is a location script with a page in the profile setup
//
function Description(var ScriptType): String;
begin
  Result:='Photos by Date';
  ScriptType:=SCRIPTTYPE_LOCATION + SCRIPTTYPE_CONFIG;
end;

function Install(Interactive);
begin
  Result:='';
end;

procedure Uninstall;
begin
end;

function FilesToExport(Interactive, Cnt);
begin
  Result:='';
end;

//-----------------------------------------------------------------------------
// Helpers
//-----------------------------------------------------------------------------

procedure ForceDir(D);
var
  P;
begin
  D:=ExcludeTrailingPathDelimiter(D);
  if (D = '') or DirectoryExists(D) then
    Exit;
  P:=ExtractFilePath(D);
  if (P <> '') and (ExcludeTrailingPathDelimiter(P) <> D) then
    ForceDir(P);
  CreateDir(D);
end;

procedure ClearFolder(D);
var
  Folder, FileItem, FilesEnum;
begin
  if not gFSO.FolderExists(D) then
    Exit;
  Folder:=gFSO.GetFolder(D);
  FilesEnum:=TEnumVariant.Create(Folder.Files);
  try
    while FilesEnum.ForEach(FileItem) do
      gFSO.DeleteFile(FileItem.Path, TRUE);
  finally
    FilesEnum.Free;
  end;
end;

function ExpandEnv(s);
var
  Shell;
begin
  Shell:=CreateOleObject('WScript.Shell');
  Result:=Shell.ExpandEnvironmentStrings(s);
  Shell:=Unassigned;
end;

function CleanPath(P);
begin
  while (Pos('\\', P) > 0) do
    P:=ReplaceStr(P, '\\', '\');
  Result:=P;
end;

function NormDir(P);
begin
  P:=CleanPath(P);
  if (P = '') then
    P:='\';
  if (Copy(P, 1, 1) <> '\') then
    P:='\' + P;
  Result:=IncludeTrailingPathDelimiter(P);
end;

function ParentDir(P);
begin
  Result:=NormDir(ExtractFilePath(ExcludeTrailingPathDelimiter(CleanPath(P))));
end;

function BaseName(P);
begin
  Result:=ExtractFileName(ExcludeTrailingPathDelimiter(CleanPath(P)));
end;

function IsRoot(P);
begin
  P:=CleanPath(P);
  Result:=(P = '') or (P = '\');
end;

function DTToText(DT);
begin
  if (DT <= 1.0) then
    Result:=''
  else
    Result:=SBSystem.UTCDateTimeToISO8601(SBSystem.LocalToGMT(DT), FALSE);
end;

function TextToDT(s);
begin
  if (s = '') then
    Result:=1.0
  else
    Result:=SBSystem.ISO8601ToLocalDateTime(s);
end;

// Field Idx (from 0) of a tab-separated line
function Field(Line, Idx);
var
  i, p, s;
begin
  s:=Line;
  for i:=1 to Idx do begin
    p:=Pos(#9, s);
    if (p = 0) then begin
      Result:='';
      Exit;
    end;
    s:=Copy(s, p + 1, Length(s));
  end;
  p:=Pos(#9, s);
  if (p = 0) then
    Result:=s
  else
    Result:=Copy(s, 1, p - 1);
end;

function YN(B);
begin
  if B then
    Result:='Y'
  else
    Result:='N';
end;

function Pad(N, Len);
begin
  Result:=IntToStr(N);
  while (Length(Result) < Len) do
    Result:='0' + Result;
end;

//-----------------------------------------------------------------------------
// The index: a file per location folder in <index>\dirs\, with a line per
// sub-folder (D, name, date) and per photo (F, name, real file, size,
// modified, created, attributes)
//-----------------------------------------------------------------------------

function DirFile(VDir);
begin
  Result:=gIndex + 'dirs\' + SBSystem.HashString(AnsiUpperCase(NormDir(VDir)), 'MD5') + '.txt';
end;

function LoadDir(VDir, L);
begin
  Result:=gFSO.FileExists(DirFile(VDir));
  if Result then
    L.Text:=ReadStringFromFile(DirFile(VDir));
end;

function FindEntry(L, Name);
var
  i, U;
begin
  Result:=-1;
  U:=AnsiUpperCase(Name);
  for i:=0 to L.Count - 1 do
    if (AnsiUpperCase(Field(L[i], 1)) = U) then begin
      Result:=i;
      Exit;
    end;
end;

// The index line of a location file (blank if there is none)
function FileLine(P);
var
  L, i;
begin
  Result:='';
  if IsRoot(P) or (Copy(P, Length(P), 1) = '\') then
    Exit;
  L:=TStringList.Create;
  try
    if LoadDir(ParentDir(P), L) then begin
      i:=FindEntry(L, BaseName(P));
      if (i >= 0) and (Field(L[i], 0) = 'F') then
        Result:=L[i];
    end;
  finally
    L.Free;
  end;
end;

function DirThere(P);
begin
  Result:=IsRoot(P) or gFSO.FileExists(DirFile(P));
end;

// A line for location folder VDir, while the index is being made
procedure IndexAdd(VDir, Line);
var
  i;
begin
  i:=gOutDirs.IndexOf(VDir);
  if (i < 0) then
    i:=gOutDirs.Add(VDir);
  gOut.Add(Pad(i, 7) + #9 + Line);
end;

// The date of a location folder: the first day of its year, month or day
function FolderDate(VDir);
var
  Parts, Y, M, D;
begin
  Result:=1.0;
  Parts:=TStringList.Create;
  try
    Parts.StrictDelimiter:=TRUE;
    Parts.Delimiter:='\';
    Parts.DelimitedText:=Copy(VDir, 2, Length(VDir) - 2);
    Y:=0;
    M:=1;
    D:=1;
    if (Parts.Count >= 1) then
      Y:=StrToIntDef(Parts[0], 0);
    if (Parts.Count >= 2) then begin
      if (gLayout = 1) then begin
        // \2024\2024-06-15\
        M:=StrToIntDef(Copy(Parts[1], 6, 2), 1);
        D:=StrToIntDef(Copy(Parts[1], 9, 2), 1);
      end else
        M:=StrToIntDef(Parts[1], 1);
    end;
    if (Parts.Count >= 3) then
      D:=StrToIntDef(Parts[2], 1);
    if (Y >= 1800) and (M >= 1) and (M <= 12) and (D >= 1) and (D <= 31) then
      Result:=EncodeDate(Y, M, D);
  finally
    Parts.Free;
  end;
end;

// Make sure location folder VDir, and the folders above it, are in the index
procedure EnsureDir(VDir);
var
  Parent;
begin
  if (gOutDirs.IndexOf(VDir) >= 0) then
    Exit;
  gOutDirs.Add(VDir);
  if IsRoot(VDir) then
    Exit;
  Parent:=ParentDir(VDir);
  EnsureDir(Parent);
  IndexAdd(Parent, 'D' + #9 + BaseName(VDir) + #9 + DTToText(FolderDate(VDir)));
end;

// Write the index made with IndexAdd: a file per folder
procedure IndexWrite;
var
  i, Cur, Text, Written, Idx;
begin
  ForceDir(gIndex + 'dirs\');
  ClearFolder(gIndex + 'dirs\');
  gOut.Sort;
  Written:=TStringList.Create;
  try
    Cur:=-1;
    Text:='';
    for i:=0 to gOut.Count - 1 do begin
      Idx:=StrToInt(Copy(gOut[i], 1, 7));
      if (Idx <> Cur) then begin
        if (Cur >= 0) then begin
          WriteStringToFile(DirFile(gOutDirs[Cur]), Text);
          Written.Add(IntToStr(Cur));
        end;
        Cur:=Idx;
        Text:='';
      end;
      Text:=Text + Copy(gOut[i], 9, Length(gOut[i])) + #13#10;
    end;
    if (Cur >= 0) then begin
      WriteStringToFile(DirFile(gOutDirs[Cur]), Text);
      Written.Add(IntToStr(Cur));
    end;
    // Folders with nothing in them (only the root can be)
    for i:=0 to gOutDirs.Count - 1 do
      if (Written.IndexOf(IntToStr(i)) < 0) then
        WriteStringToFile(DirFile(gOutDirs[i]), '');
  finally
    Written.Free;
  end;
end;

//-----------------------------------------------------------------------------
// Making the index
//-----------------------------------------------------------------------------

// The location folder for a date taken, as yyyymmddhhnnss (blank = none)
function DateDir(When);
var
  Y, M, D;
begin
  if (When = '') then begin
    Result:='\' + NO_DATE + '\';
    Exit;
  end;
  Y:=Copy(When, 1, 4);
  M:=Copy(When, 5, 2);
  D:=Copy(When, 7, 2);
  if (gLayout = 1) then
    Result:='\' + Y + '\' + Y + '-' + M + '-' + D + '\'
  else if (gLayout = 2) then
    Result:='\' + Y + '\' + M + '\' + D + '\'
  else
    Result:='\' + Y + '\' + M + '\';
end;

//
// Find every photo, read (or remember) its date taken, and put it in the
// index under the folder for that date
//
function BuildIndex;
var
  Files, i, Path, F, Size, MTime, Key, k, TakenText, Taken, When, Photos,
  CacheLines, CacheKeys, NewCache, Line, VDir, Name, Base, Ext, n, Cand, Masks;
begin
  Result:='';
  Masks:=PHOTO_MASKS;
  if gVideos then
    Masks:=Masks + ';' + VIDEO_MASKS;

  Files:=TStringList.Create;
  Photos:=TStringList.Create;
  CacheLines:=TStringList.Create;
  CacheKeys:=TStringList.Create;
  NewCache:=TStringList.Create;
  gOutDirs:=TStringList.Create;
  gOut:=TStringList.Create;
  gUsed:=TStringList.Create;
  try
    SBSystem.UpdateFileStatus('Finding the photos...');
    Files.Text:=SBSystem.FindFiles(gSource, Masks, TRUE);

    // The dates taken read before: <32 hex key><tab><yyyymmddhhnnss or 0>.
    // Sorted, the keys (all the same length) are in the same order as the
    // lines, so a key's position is its line's.
    if gFSO.FileExists(gIndex + 'dates.txt') then
      CacheLines.Text:=ReadStringFromFile(gIndex + 'dates.txt');
    CacheLines.Sort;
    for i:=0 to CacheLines.Count - 1 do
      CacheKeys.Add(Copy(CacheLines[i], 1, 32));
    CacheKeys.Sorted:=TRUE;

    SBSystem.UpdateFileStatus('Reading when each photo was taken...');
    for i:=0 to Files.Count - 1 do begin
      Path:=Files[i];
      // Mac resource files (._IMG_1234.JPG) are not photos
      if (Copy(ExtractFileName(Path), 1, 2) = '._') then
        continue;
      try
        F:=gFSO.GetFile(Path);
        Size:=VarToInt64(F.Size);
        MTime:=F.DateLastModified;
      except
        continue; // deleted since it was found
      end;

      Key:=SBSystem.HashString(AnsiUpperCase(Path) + '|' + IntToStr(Size) + '|' + DTToText(MTime), 'MD5');
      k:=CacheKeys.IndexOf(Key);
      if (k >= 0) then
        TakenText:=Copy(CacheLines[k], 34, 14)
      else begin
        Taken:=SBSystem.GetDateTaken(Path);
        if (Taken = 0) then
          TakenText:='0'
        else
          TakenText:=FormatDateTime('yyyymmddhhnnss', Taken);
      end;
      NewCache.Add(Key + #9 + TakenText);

      if (TakenText <> '0') then
        When:=TakenText
      else if gNoDateFolder then
        When:=''
      else
        When:=FormatDateTime('yyyymmddhhnnss', MTime);

      // Sorted by date, then path: the photo taken first keeps its name
      if (When = '') then
        When:='00000000000000';
      Photos.Add(When + #9 + Path + #9 + IntToStr(Size) + #9 +
        DTToText(MTime) + #9 + DTToText(F.DateCreated) + #9 + IntToStr(F.Attributes));
    end;
    Photos.Sort;

    EnsureDir('\');
    gUsed.Sorted:=TRUE;
    for i:=0 to Photos.Count - 1 do begin
      Line:=Photos[i];
      When:=Field(Line, 0);
      if (When = '00000000000000') then
        When:='';
      VDir:=DateDir(When);
      EnsureDir(VDir);

      Name:=ExtractFileName(Field(Line, 1));
      Ext:=ExtractFileExt(Name);
      Base:=Copy(Name, 1, Length(Name) - Length(Ext));
      Cand:=Name;
      n:=1;
      while (gUsed.IndexOf(AnsiUpperCase(VDir + Cand)) >= 0) do begin
        n:=n + 1;
        Cand:=Base + ' (' + IntToStr(n) + ')' + Ext;
      end;
      gUsed.Add(AnsiUpperCase(VDir + Cand));

      IndexAdd(VDir, 'F' + #9 + Cand + #9 + Field(Line, 1) + #9 + Field(Line, 2) + #9 +
        Field(Line, 3) + #9 + Field(Line, 4) + #9 + Field(Line, 5));
    end;

    IndexWrite;
    WriteStringToFile(gIndex + 'dates.txt', NewCache.Text);
    WriteStringToFile(gIndex + 'folder.txt', gSource);
  finally
    gUsed.Free;
    gOut.Free;
    gOutDirs.Free;
    NewCache.Free;
    CacheKeys.Free;
    CacheLines.Free;
    Photos.Free;
    Files.Free;
  end;
end;

//-----------------------------------------------------------------------------
// Connecting
//-----------------------------------------------------------------------------

function LoadSettings;
begin
  Result:='';
  gSource:=Trim(SBVariables.GetProperty('PhotosSource', '', FALSE));
  if (gSource = '') then begin
    Result:='Photos by Date: choose the folder with your photos on the Photos by Date page of the profile setup';
    Exit;
  end;
  gSource:=IncludeTrailingPathDelimiter(ExpandEnv(gSource));
  gLayout:=StrToIntDef(SBVariables.GetProperty('PhotosLayout', '0', FALSE), 0);
  gVideos:=(UpperCase(SBVariables.GetProperty('PhotosVideos', 'Y', FALSE)) <> 'N');
  gNoDateFolder:=(UpperCase(SBVariables.GetProperty('PhotosNoDateFolder', 'N', FALSE)) = 'Y');
  // One index per photo folder and layout
  gIndex:=IncludeTrailingPathDelimiter(ExpandEnv('%LOCALAPPDATA%\SyncBack Photos by Date')) +
    SBSystem.HashString(AnsiUpperCase(gSource) + '|' + IntToStr(gLayout) + '|' + YN(gVideos) +
      '|' + YN(gNoDateFolder), 'SHA1') + '\';
end;

function LocConnect(MainThread);
begin
  gFSO:=CreateOleObject('Scripting.FileSystemObject');
  gMade:=FALSE;
  Result:=LoadSettings;
  if (Result <> '') then
    Exit;
  if not DirectoryExists(gSource) then begin
    Result:='Photos by Date: the folder ' + gSource + ' does not exist';
    Exit;
  end;
  ForceDir(gIndex + 'dirs\');
  if not DirectoryExists(gIndex + 'dirs\') then
    Result:='Photos by Date: cannot create its index folder ' + gIndex;
end;

function LocDisconnect;
begin
  gFSO:=Unassigned;
  Result:='';
end;

//
// Called before SyncBack lists the location: find the photos (once per
// connection, so the Differences window does not do it again)
//
function LocScanPrepare;
begin
  Result:='';
  if not gMade then begin
    Result:=BuildIndex;
    gMade:=(Result = '');
  end;
end;

function LocConnected;
begin
  Result:='';
end;

function LocReconnect;
begin
  Result:='';
end;

//-----------------------------------------------------------------------------
// Reading
//-----------------------------------------------------------------------------

function LocDirExists(FullPath);
begin
  if DirThere(FullPath) then
    Result:=''
  else
    Result:='Folder does not exist';
end;

function LocFileExists(FullPath);
begin
  if (FileLine(FullPath) <> '') then
    Result:=''
  else
    Result:='File does not exist';
end;

function LocScanList(FullPath);
var
  L, i, Line;
begin
  Result:='';
  L:=TStringList.Create;
  try
    if not LoadDir(NormDir(FullPath), L) then begin
      if not IsRoot(FullPath) then
        Result:='Folder does not exist';
      Exit;
    end;
    for i:=0 to L.Count - 1 do begin
      Line:=L[i];
      if (Field(Line, 0) = 'D') then begin
        if not SBLocation.AddDirEx2(Field(Line, 1), 16, TextToDT(Field(Line, 2)), TextToDT(Field(Line, 2)), '') then
          Exit;
      end else if (Field(Line, 0) = 'F') then begin
        if not SBLocation.AddFileEx(Field(Line, 1), '', VarToInt64(Field(Line, 3)), StrToInt(Field(Line, 6)),
          TextToDT(Field(Line, 4)), TextToDT(Field(Line, 5)), '') then
          Exit;
      end;
    end;
  finally
    L.Free;
  end;
end;

function LocGet(fromFName, toFName);
var
  Line, r;
begin
  Line:=FileLine(fromFName);
  if (Line = '') then begin
    Result:='File does not exist';
    Exit;
  end;
  r:=CopyFile(Field(Line, 2), toFName);
  if (r = 0) then
    Result:=''
  else
    Result:=SysErrorMessage(r);
end;

function LocCRC32(FullPath; var CRC32);
var
  Line;
begin
  Line:=FileLine(FullPath);
  if (Line = '') then begin
    Result:='File does not exist';
    Exit;
  end;
  CRC32:=SBSystem.CRC32(Field(Line, 2));
  Result:='';
end;

function LocGetAttributes(Filename; var Attrs);
var
  Line;
begin
  Result:='';
  Line:=FileLine(Filename);
  if (Line <> '') then
    Attrs:=StrToInt(Field(Line, 6))
  else if DirThere(Filename) then
    Attrs:=16
  else
    Result:='File or folder does not exist';
end;

function LocFreeSpace;
begin
  Result:=-1;
end;

function LocAbilities;
begin
  Result:=CAN_USEATTRIBUTES + CAN_HAVEEMPTYPATH + CAN_USECRC32;
end;

//-----------------------------------------------------------------------------
// Writing: none of it is allowed
//-----------------------------------------------------------------------------

function LocMakeDir(FullPath);
begin
  if DirThere(FullPath) then
    Result:=''
  else
    Result:=READ_ONLY;
end;

function LocRemoveDir(FullPath);
begin
  Result:=READ_ONLY;
end;

function LocRenameDir(FromPath, ToPath);
begin
  Result:=READ_ONLY;
end;

function LocRenameFile(FromName, ToName);
begin
  Result:=READ_ONLY;
end;

function LocDeleteFile(FullPath; var DoesNotExist);
begin
  DoesNotExist:=(FileLine(FullPath) = '');
  if DoesNotExist then
    Result:=''
  else
    Result:=READ_ONLY;
end;

function LocSetModDateTime(FullPath, ModDateTime);
begin
  Result:=READ_ONLY;
end;

function LocSetCreateDateTime(FullPath, CreateDateTime);
begin
  Result:=READ_ONLY;
end;

function LocSetAttributes(Filename, Attrs);
begin
  Result:=READ_ONLY;
end;

function LocPutEx(fromFName, toFName, fromAttrs, fromDateTime, fromCreateDateTime, fromFileSize, fromNTFSSec, DoSafeCopy; var SafeFName);
begin
  SafeFName:='';
  Result:=READ_ONLY;
end;

//-----------------------------------------------------------------------------
// The Photos by Date page in the profile setup
//-----------------------------------------------------------------------------

// Only in profiles that use Photos by Date as their location
function ConfigWantSetupNode(IsGroup);
begin
  Result:=not IsGroup and SBProfile.UsesScript;
end;

function ConfigNodeCaption;
begin
  Result:='Photos by Date';
end;

function ConfigCanRevert;
begin
  Result:=TRUE;
end;

function ConfigCanClose;
begin
  Result:=TRUE;
end;

procedure ConfigFactoryDefaults;
begin
  SBVariables.DeleteProperty('PhotosSource');
  SBVariables.DeleteProperty('PhotosLayout');
  SBVariables.DeleteProperty('PhotosVideos');
  SBVariables.DeleteProperty('PhotosNoDateFolder');
end;

procedure ConfigSetupDisplay;
begin
  SBProfile.AddLabel('Your photos in folders by the date they were taken. The photos themselves are not changed.', 20);
  SBProfile.AddEdit('Folder with your photos (its sub-folders are included)', 260, FALSE, FALSE, 1);
  SBProfile.AddRadioGroup('Folders', 2);
  SBProfile.AddRadioGroupItem('Year\Month, e.g. 2024\06', 2);
  SBProfile.AddRadioGroupItem('Year\Date, e.g. 2024\2024-06-15', 2);
  SBProfile.AddRadioGroupItem('Year\Month\Day, e.g. 2024\06\15', 2);
  SBProfile.AddCheckbox('Include videos (MP4, MOV and so on)', 3);
  SBProfile.AddCheckbox('Put photos with no date taken in a "No date taken" folder (otherwise they go by the date of the file)', 4);
end;

function ConfigLoadSettings;
begin
  Result:='';
  SBProfile.SetEdit(SBVariables.GetProperty('PhotosSource', '', FALSE), 1);
  SBProfile.SetRadioGroup(StrToIntDef(SBVariables.GetProperty('PhotosLayout', '0', FALSE), 0), 2);
  SBProfile.SetCheckbox(UpperCase(SBVariables.GetProperty('PhotosVideos', 'Y', FALSE)) <> 'N', 3);
  SBProfile.SetCheckbox(UpperCase(SBVariables.GetProperty('PhotosNoDateFolder', 'N', FALSE)) = 'Y', 4);
end;

// Store a setting in the profile. One that has never been set and is still
// the default is left unset, so just looking at this page and pressing Cancel
// does not count as a change to the profile.
procedure SaveSetting(Name, Value, Default);
begin
  if (SBVariables.GetProperty(Name, '!NOTSET!', FALSE) = '!NOTSET!') and (Value = Default) then
    Exit;
  SBVariables.SetProperty(Name, Value);
end;

function ConfigSaveSettings(Silent);
var
  Layout;
begin
  Result:='';
  if (Trim(SBProfile.GetEdit(1)) = '') and not Silent then begin
    Result:='Photos by Date: choose the folder with your photos';
    Exit;
  end;
  Layout:=SBProfile.GetRadioGroup(2);
  if (Layout < 0) then
    Layout:=0;
  SaveSetting('PhotosSource', Trim(SBProfile.GetEdit(1)), '');
  SaveSetting('PhotosLayout', IntToStr(Layout), '0');
  SaveSetting('PhotosVideos', YN(SBProfile.GetCheckbox(3)), 'Y');
  SaveSetting('PhotosNoDateFolder', YN(SBProfile.GetCheckbox(4)), 'N');
end;

procedure ConfigUpdateConditionals;
begin
end;
