electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.61k stars 1.74k forks source link

$BUILD_RESOURCES_DIR is a constant value and always points to the project build folder (Which may cause unexpected failure if you use it in your NSIS script) #1050

Closed imwithye closed 7 years ago

imwithye commented 7 years ago

I need copy a file to C:\ProgramData, and I create this NSIS script to do this:

!macro customInstall
    CreateDirectory `C:\ProgramData\Autodesk\Revit\Addins\2016`
    CreateDirectory `C:\ProgramData\Autodesk\Revit\Addins\2017`
    CopyFiles `${BUILD_RESOURCES_DIR}\Revit\2016\VRcollab.addin` `C:\ProgramData\Autodesk\Revit\Addins\2016`
    CopyFiles `${BUILD_RESOURCES_DIR}\Revit\2017\VRcollab.addin` `C:\ProgramData\Autodesk\Revit\Addins\2017`
!macroend

!macro customUnInstall
    Delete `C:\ProgramData\Autodesk\Revit\Addins\2016\VRcollab.addin`
    Delete `C:\ProgramData\Autodesk\Revit\Addins\2017\VRcollab.addin`
!macroend

This script may fail if the admin permission cannot be acquired. Can anyone help me to modify the script so that it will copy the file correctly?

Really thanks!

develar commented 7 years ago

Do you use one-click installer?

imwithye commented 7 years ago

@develar Thanks.

Yes I do. And I also use fileAssociations key and set perMachine as true. It will popup the admin permission window but I found out it still cannot copy the file on a fresh new machine.

develar commented 7 years ago

If you use perMachine is means that installer is executed using admin rights. So, your issue is definitely not about rights (well, windows ***, but I still hope). Could you please provide full error text?

imwithye commented 7 years ago

@develar I not sure how to get the error text of the installer. There is no error during the installation and the file is just not copied.

This happened on fresh new machines (never install this software before), and once I create the file manually and after that it can copy the file without problem.

develar commented 7 years ago

CopyFiles works on the installing system. You should not include Revit\2016\VRcollab.addin and Revit\2017\VRcollab.addin as part of your app. Instead, please try to use http://nsis.sourceforge.net/Reference/File

imwithye commented 7 years ago

@develar Now I can reproduce this bug. The problem is ${BUILD_RESOURCES_DIR} is a constant and always point to the original build directory. In this case, if I move the installer to a new computer without ${BUILD_RESOURCES_DIR}, this command will fail.

One possible solution is to use the File API as you mentioned.

I will post a solution after I fix this and close this issue. Thank you so much @develar. And one more suggestion is to point out the usage of ${BUILD_RESOURCES_DIR} in the documentation.

imwithye commented 7 years ago

Eh, the CopyFiles works on the runtime installing process but not the installer creation time. This is exactly what I need. But seems like customInstall command, mentioned here, https://github.com/electron-userland/electron-builder/wiki/NSIS works on the installer creation time because the echo command happened when I run build to build the installer.

And from the error log, I can't see any runtime variable, like $INSTDIR, so in this case I cannot set runtime filepath relative $INSTDIR. Anyway to get the runtime information and copy the file during run time?

Output:                                                                                                                    
Command line defined: "APP_ID=com.vrcollab"                                                                                
Command line defined: "APP_GUID=5907c58d-96e0-5c0c-9759-509c00703aef"                                                      
Command line defined: "PRODUCT_NAME=VRcollab"                                                                              
Command line defined: "PRODUCT_FILENAME=VRcollab"                                                                          
Command line defined: "APP_FILENAME=VRcollab"                                                                              
Command line defined: "APP_DESCRIPTION=VRcollab Application"                                                               
Command line defined: "VERSION=0.1.0"                                                                                      
Command line defined: "COMPANY_NAME=VRcollab"                                                                              
Command line defined: "PROJECT_DIR=D:\VRcollab\VRcollab"                                                                   
Command line defined: "BUILD_RESOURCES_DIR=D:\VRcollab\VRcollab\build"                                                     
Command line defined: "MUI_ICON=D:\VRcollab\VRcollab\build\icon.ico"                                                       
Command line defined: "MUI_UNICON=D:\VRcollab\VRcollab\build\icon.ico"                                                     
Command line defined: "APP_64=D:\VRcollab\VRcollab\dist\VRcollab-0.1.0-x64.nsis.7z"                                        
Command line defined: "INSTALL_MODE_PER_ALL_USERS"                                                                         
Command line defined: "INSTALL_MODE_PER_ALL_USERS_REQUIRED"                                                                
Command line defined: "RUN_AFTER_FINISH"                                                                                   
Command line defined: "COMPRESS=auto"                                                                                      
Command line defined: "ONE_CLICK"                                                                                          
Command line defined: "UNINSTALLER_OUT_FILE=C:\Users\Ciel\AppData\Local\Temp\electron-builder-rO9RxY\0-1-uninstaller.exe"  
Processing config: C:\Users\Ciel\AppData\Local\electron-builder\cache\nsis\nsis-3.0.2\nsisconf.nsh                         
Processing script file: "<stdin>" (ACP)                                                                                    
warning: unknown variable/constant "{OUTDIR}" detected, ignoring (macro:customInstall:1)                                   
Error: warning treated as error                                                                                            
imwithye commented 7 years ago

Fixed by putting the file under extra_resources folder and copy it during runtime(installation time).

!macro customInstall
    CreateDirectory "C:\ProgramData\Autodesk\Revit\Addins\2016"
    CreateDirectory "C:\ProgramData\Autodesk\Revit\Addins\2017"
    CopyFiles "$INSTDIR\resources\extra_resources\Revit\2016\VRcollab.addin" "C:\ProgramData\Autodesk\Revit\Addins\2016"
    CopyFiles "$INSTDIR\resources\extra_resources\Revit\2017\VRcollab.addin" "C:\ProgramData\Autodesk\Revit\Addins\2017"
!macroend

!macro customUnInstall
    Delete "C:\ProgramData\Autodesk\Revit\Addins\2016\VRcollab.addin"
    Delete "C:\ProgramData\Autodesk\Revit\Addins\2017\VRcollab.addin"
!macroend
develar commented 7 years ago

I still think that solution using File is better (except compression) :)

Fer0x commented 7 years ago

Solved for me using File command:

!macro customInstall
  MessageBox MB_YESNO "Install additional drivers?" /SD IDYES IDNO endInstall
    File "${BUILD_RESOURCES_DIR}\driver.msi"
    ExecWait '"msiexec" /i driver.msi'
  endInstall:
!macroend