Skip to content
⌘ NSIS Forum Archive

Issue with installing fonts (FontReg)

4 posts

Mircea M#

Issue with installing fonts (FontReg)

I need to install multiple fonts through NSIS, all found in a folder. The content of the folder may change so I don't want to define each font in the NSIS script by name.
I am using (or trying to use) the FontReg plugin.
My nsi looks like this:

!include FontName.nsh
!include FontReg.nsh
!include WinMessages.nsh
!define Fonts_Folder "$EXEDIR\fonts"
OutFile Install_Font.exe

Function Install_GE_Fonts
FindFirst $0 $1 "${Fonts_Folder}\*.TTF"
DetailPrint "Installing ${Fonts_Folder}\$1"
!insertmacro InstallTTFFont "${Fonts_Folder}\$1"

Loop:
IfErrors Done
FindNext $0 $1
IfFileExists "${Fonts_Folder}\$1" IsFile Done
IsFile:
DetailPrint "Installing ${Fonts_Folder}\$1"
!insertmacro InstallTTFFont "${Fonts_Folder}\$1"
Goto Loop

Done:
FindClose $0

SendMessage ${HWND_BROADCAST} ${WM_FONTCHANGE} 0 0 /TIMEOUT=5000
FunctionEnd

Section
StrCpy $FONT_DIR $FONTS
Call Install_GE_Fonts
SectionEnd
When I try to compile this I get the following error:
!define: "FontFileName"="$0"
SetOutPath: "$FONT_DIR"
IfFileExists: "$FONT_DIR\$0" ? Line10.6 :
File: "$EXEDIR\fonts\$1" -> no files found.
Usage: File [/nonfatal] [/a] ([/r] [/x filespec [...]] filespec [...] |
/oname=outfile one_file_only)
Error in macro InstallTTFFont on macroline 14
If I execute the code with the InstallTTFFont macro lines commented out, I get the full paths and file names of all the fonts I need to install.

Can someone please help?

Thank you!
Mircea M#
Some additional Info: if instead of $1 I use an actual filename, the script works. So the problem lies with the macro interpreting the variable and using its value...
The "weird" part is that it correctly interprets ${Fonts_Folder} but not $1...
Anders#
The File command does not accept variables since it has to know the path to the file at compile time.

You might have to create your own version of the InstallTTFFont macro that does not do the "File" step. Instead you do File source\myfonts\*.ttf before the FindFirst loop...
Mircea M#
Well, the files are going to be in a separate folder on the DVD so I guess I can skip the File command then, right?