Installing Fonts using NSIS - nsis

I am installing fonts in my setup application using:
Section "Fonts"
SetOutPath "$FONTS"
StrCpy $FONT_DIR $FONTS
!insertmacro InstallTTFfont '..\FONTS\English\Arial.ttf'
SendMessage ${HWND_BROADCAST} ${WM_FONTCHANGE} 0 0 /TIMEOUT=5000
SectionEnd
(I have included !include FontReg.nsh and !include FontName.nsh)
At times, especially on Win 7(with UAC enabled), the setup progress goes into a non-reponsive mode(progress bar remains frozen at the end of the font installation and setup does not proceed). Is there anything to avoid this scenario?. Kindly help.
Thanks,
Bomzinho

There is some macros dedicated for registering fonts available on the NSIS wiki. They do a bit more than just copying the .ttf file.
Also you could look at the page on http://nsis.sourceforge.net/Advanced_Font_Installation

Related

Electron-builder NSIS, embedding other installers

I have created a little electron program for one of my friends, it is a patcher for a private metin2 server of some sort. The game itself is really old so it requires a few redisturables to be installed.
[dxwebsetup0411 / dotNetFx35setup / vcredist_x86 ( i believe its a 2013 version) ]
I want to include them as an option at the end of the install (or even before it, doesn't really matter).
I have found a few examples how to do so but they are all for Standalone NSIS installers and when i try to include that script ( in the build/installer.nsh file ), the build process crashes, presumably because its not the main build script therefor adding Sections is prohibited (?).
Im really new to NSIS scripts and NSIS overall.
So far i only figured out how to put checkboxes and labels and so on in, with the help of nsDialogs, but as i looked at its documentation, it seemed that there are no option where i could do this.
Any help would be greatly appreciated.
EDIT :
My script currently is almost empty, I only changed the default directory, but anyway here is that:
!macro preInit
SetRegView 64
WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\Decay2"
WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\Decay2"
SetRegView 32
WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\Decay2"
WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\Decay2"
!macroend
Everything i know about electron-builder's NSIS main script and this included script is here :
Custom Script Example
NSIS- Electron Builder
It is definitely possible to embed other installers and execute them. See this example on SO:
Embedding other installers using NSIS
or these official NSIS tutorials/guides: https://nsis.sourceforge.io/Embedding_other_installers
Please post your script and build file(s) if you have some issue with your script and you expect specific answer.

Add NSIS script with electron builder to run DPInst.exe during install

I'm using electron-builder to create NSIS Windows installers for my electron app. During install I need to run the included DPInst.exe to make sure drivers get installed.
I can tell electron-builder than I'm including a custom script:
"nsis": {
"include": "build/installer.nsh"
}
But I can't work out what should be in the installer.nsh
The docs say that I need something like:
!macro customInstall
!system "echo '' > ${BUILD_RESOURCES_DIR}/customInstall"
!macroend
And I've seen some NSIS commands to run DPInst.exe
ExecWait '"$INSTDIR\resources\DPInst.exe" /sw'
But I'm unsure how to combine them as I can't work out the syntax!
Well, it was pretty obvious 🤦‍♂️. I just had to combine the two:
!macro customInstall
ExecWait '"$INSTDIR\resources\DPInst.exe" /sw'
!macroend
For me, ExecWait '"$INSTDIR\resources\DPInst.exe" /sw' alone wasn't working because of permission issues.
I had to add RequestExecutionLevel admin
installer.nsh looks like -
!macro customHeader
RequestExecutionLevel admin
!macroend
!macro customInstall
ExecWait '"$INSTDIR\ABC_Setup.exe" /sw'
!macroend

NSIS uninstaller doesn't run un.onInit

In my .nsi file I have the following logic in the un.onInit function:
Function un.onInit
MessageBox MB_YESNO "This will uninstall. Continue?" IDYES checkRunning
checkRunning:
FindProcDLL::FindProc "app.exe"
IntCmp $R0 1 0 notRunning
MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "${PRODUCT} is running, please close it so the installation can proceed." /SD IDCANCEL IDRETRY checkRunning
Abort
notRunning:
!insertmacro Init "uninstaller"
FunctionEnd
However, the messageBox (and the process is running message) is never shown. So I went through a lot of documentation and apparently running silent mode prevents this method being called so I added SilentInstall normal and SilentUnInstall normal to the .nsi file. However, this doesn't work either.
I tried invoking the uninstaller by manually going to the uninstall.exe and by running the installer which checks if there is already a version installed and if there is calling:
uninst:
ClearErrors
ExecWait '$R0 _?=$INSTDIR' ;Do not copy the uninstaller to a temp file
ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" "UninstallString"
StrCmp $R0 "" done
Abort
Yet both of these invokes do not trigger to 'normal' mode. So how can I get my un.onInit function to be called?
Edit:
As someone asked for the whole file, here it is. I copied the relevant parts only, but if more is needed feel free to check it out. Note that the whole file is already quite old, I am merely updating it.
After upgrading the MUI2 (Modern User Interface 2.0), downgrading to NSIS 2.5 and using the NsProcess plug-in, I got it working. The function is now being called and my check works using the new plugin. The FindProcDLL plugin is broken on NSIS > 2.46

Error installing a font with NSIS

I am working on my first NSIS script and I have it working to install my Windows form project, but now I also want it to install a specific font during the installation. I keep getting the following error, even though my code appears to match every example I can find.
Invalid command: FontName::Name
Error in macro FontName on macroline 3
Error in macro InstallTTFFont on macroline 30
Here is the code I have added for the install of the font:
!include FontReg.nsh
!include FontName.nsh
!include WinMessages.nsh
Section "Fonts"
StrCpy $FONT_DIR $FONTS
!insertmacro InstallTTFFont "myFont-B.TTF"
SendMessage ${HWND_BROADCAST} ${WM_FONTCHANGE} 0 0 /TIMEOUT=5000
SectionEnd
Invalid command: xxx::yyy means it cannot find the xxx plugin. Did you put the FontName plugin .dll in the correct plugin directory?

NSIS - Silent Autoupdate Application

I have an NSIS install kit for my .net c# application.
Is there a way to silently autoupdate my application, considering that I already downloaded the new update (new NSIS app version) to local computer ?
Thanks! :)
(In case you need to detect the command line /Autoupdate=yes)
!include FileFunc.nsh
!insertmacro GetParameters
!insertmacro GetOptions
Var CMD_ARGS
Var CMD_RES
Function .onInit
#
#installer stuff.
#
StrCpy $CMD_ARGS ""
StrCpy $CMD_RES "no"
${GetParameters} $CMD_ARGS
ClearErrors
${GetOptions} $CMD_ARGS /Autoupdate= $CMD_RES
StrCmp $CMD_RES "yes" is_update is_not_update
is_update:
#Execute all your update code(run your update app, etc)
MessageBox MB_OK|MB_ICONEXCLAMATION "IS UPDATE"
goto end_auto_update_check
is_not_update:
#Execute all your non-update code.
MessageBox MB_OK|MB_ICONEXCLAMATION "IS NOT UPDATE"
end_auto_update_check:
FunctionEnd
You can run the installer silently and install on top if that is what you mean:
foo.exe /S /D=C:\Program Files\Foo
It's not necessary to pass /S to the command line if you've set up the package script to specify silent installs.
Take a look at the silent.nsi example on the NSIS site silent.nsi

Resources