electronnsis

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!


Solution


  • !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.