Install font with Inno Setup if the version of the font in the setup is higher than one installed

Viewed 118

I have a custom font that is installed with my Inno Setup, and I would like to overwrite the existing font only if the font in my setup was upgraded.

Font properties

In order to do this, I have tried to get the version from my font file but GetVersionNumbersString in a function or GetFileVersionString in the Inno Setup preprocessor. As far as I have understood, those functions only apply to exe or dll but I might be wrong.

Any lead to help me achieve this would be very much appreciated.

Thanks,

Olivier

1 Answers

You can use the following code to extract TTF file (possibly any file) version:

function GetShellItemVersion(Path: string): string;
var
  Shell, Folder, Item, Version: Variant;
  FolderPath: string;
begin
  Shell := CreateOleObject('Shell.Application');
  FolderPath := ExtractFilePath(Path);
  Folder := Shell.NameSpace(FolderPath);
  if VarIsClear(Folder) then
  begin
    Log(Format('Error reading folder "%s"', [FolderPath]));
  end
    else
  begin
    Item := Folder.ParseName(ExtractFileName(Path));
    if VarIsClear(Item) then
    begin
      Log(Format('Error accessing "%s"', [Path]));
    end
      else
    begin
      Version := Folder.GetDetailsOf(Item, 166);
      if VarIsClear(Version) then
      begin
        Log(Format('Error reading version of "%s"', [Path]));
      end
        else
      begin
        Result := Version;
        Log(Format('Version of "%s" is "%s"', [Path, Result]));
      end;
    end;
  end;
end;

Based on Get details of uninstalled Windows fonts via PowerShell.

Related