Inbal Meshulach
Inbal Meshulach

Reputation: 3

NSIS make D: the default installation path

I have an electron app, I want the default installation path to be D: if it exist, instead of C:

My current installer.nsh file is:

Section
    System::Call 'kernel32::GetFileAttributes(t "D:\")i .r0'
    
    IntCmp $0 -1 NoDInstalled DriveDInstalled
    
    NoDInstalled:
        StrCpy $INSTDIR "$PROGRAMFILES\"
        Goto ContinueInstallation

    DriveDInstalled:
        StrCpy $INSTDIR "D:\"
        Goto ContinueInstallation
    
  ContinueInstallation:
    SetOutPath $INSTDIR
SectionEnd

I have a D: external drive connected to my computer and the default is still C:

Would love some help!

Upvotes: 0

Views: 151

Answers (1)

Anders
Anders

Reputation: 101569

  • You should set the default $InstDir in .onInit, not in a Section.
  • You should provide 3 jump labels to IntCmp.
  • You should not install to the root of $PROGRAMFILES

!macro customInit
System::Call 'kernel32::GetFileAttributes(t "D:\")i.r0'
${If} $0 <> -1
  StrCpy $INSTDIR "D:\"
${Else}
   StrCpy $INSTDIR "$PROGRAMFILES\$(^Name)"
${EndIf}
!macroend

In real NSIS you would just

Function .onInit
!insertmacro customInit
FunctionEnd

but since you are using electron I have no idea where you actually put this macro, the documentation is not clear if it is in installer.nsh or somewhere else. Their code makes it look like it should be somewhere else, you probably have to ask them directly for support if you can't figure it out yourself.

Upvotes: 0

Related Questions