Recent

Author Topic: [SOLVED] VerifyAndCleanUpFontDirectories doesn't check all list entries  (Read 1797 times)

lagprogramming

  • Sr. Member
  • ****
  • Posts: 407
lcl/interfaces/customdrawn/customdrawnproc.pas has
Code: Pascal  [Select][+][-]
  1. procedure VerifyAndCleanUpFontDirectories(AFontDirectories: TStringList);
  2. var
  3.   i, j: Integer;
  4. begin
  5.   // Add path delimitiers to the end of all paths
  6.   for i := 0 to AFontDirectories.Count -1 do
  7.   begin
  8.     AFontDirectories.Strings[i] := IncludeTrailingPathDelimiter(AFontDirectories.Strings[i]);
  9.   end;
  10.  
  11.   // remove all duplicates
  12.   i := 0;
  13.   while i < AFontDirectories.Count do
  14.   begin
  15.     j := i+1;
  16.     while j < AFontDirectories.Count do
  17.     begin
  18.       if AFontDirectories.Strings[i] = AFontDirectories.Strings[j] then
  19.         AFontDirectories.Delete(j);
  20.       Inc(j);
  21.     end;
  22.     Inc(i);
  23.   end;
  24.  
  25.   // Now remove all directories which don't exist
  26.   i := 0;
  27.   while i < AFontDirectories.Count do
  28.   begin
  29.     if not DirectoryExistsUTF8(AFontDirectories.Strings[i]) then
  30.       AFontDirectories.Delete(i);
  31.     Inc(i);
  32.   end;
  33.  
  34.   // Raise an exception if there are no font directories
  35.   if AFontDirectories.Count = 0 then
  36.     raise Exception.Create('[VerifyAndCleanUpFontDirectories] After cleaning up no font directories were found.');
  37. end;
The original code doesn't remove all nonexistent or duplicate directories because immediately after a delete the list index is increased, thus skipping a list entry. The following patch keeps the index unchanged if the list deletes an entry. Now each and every tstringlist entry is verified.
« Last Edit: January 14, 2024, 10:26:24 am by lagprogramming »


 

TinyPortal © 2005-2018