Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a custom NSIS include #1231

Closed
sklink opened this issue Feb 9, 2017 · 16 comments
Closed

Creating a custom NSIS include #1231

sklink opened this issue Feb 9, 2017 · 16 comments

Comments

@sklink
Copy link

sklink commented Feb 9, 2017

  • Version: 13.3.1
  • Target: Windows x64 & ia32

I'm trying to integrate this for install / uninstall analytics: https://github.com/nmoinvaz/nsis-mp

From what I've gathered so far, build in an includedir, so I can just add the file to the build folder and write !include "mp.nsh" to the top of build/installer.nsh and it'll include their script.

Next I see that nsis-mp requires:

The docs say LogicLib.nsh ships with NSIS so no problem there, just using !include "LogicLib.nsh" at the top of the mp.nsh document. However, it seems the others need to be added.

I cannot find !addplugindir anywhere in the electron-builder code and I don't know whether those plugins are already available within electron-builder. Do I need to modify the main script to add these plugins or is there a method of doing it in the build/installer.nsh file? (if it even needs to be done at all)

The final step has been to create the custom macros in build/installer.nsh:

!include "mp.nsh"

!macro customInstall
    !insertmacro MixPanelAnalytics "827378183a4g4g348fha329a3of0e9a" "Install"
!macroend
!macro customUnInstall
    ${GetParameters} $R0
    ${GetOptions} $R0 "--update" $R1
    ${IfNot} ${Errors}
        !insertmacro MixPanelAnalytics "827378183a4g4g348fha329a3of0e9a" "Update"
    ${Else}
        !insertmacro MixPanelAnalytics "827378183a4g4g348fha329a3of0e9a" "Uninstall"
    ${endif}
!macroend

I've been unable to figure out how to debug a NSIS installation. That alone will help me make progress. I'll update this as I make progress, but any help is appreciated. I can only afford a small donation but I'll throw one your way right away.

@develar
Copy link
Member

develar commented Feb 10, 2017

LogicLib.nsh is not required to be added since it is already added by default.

inetc is a part of installation since 13.3.0.

base64 should be added explicitly, but you should not use one from https://github.com/nmoinvaz/nsis-base64 because it is not UNICODE build. But I guess you can try it.

Build resources dir is added as addincludedir by default (if custom include script is specified). So,

  1. just put https://github.com/nmoinvaz/nsis-base64/blob/master/base64.dll and mp.nsh into the build directory.
  2. create the custom macros in build/installer.nsh

Did you get compilation error or build was successful?

@sklink
Copy link
Author

sklink commented Feb 10, 2017

Build was successful. It installs successfully too and runs just fine. MixPanel isn't receiving the data though.

I ended up using this Base64 script instead: http://nsis.sourceforge.net/Base64

I think next steps are:

  1. See whether the MixPanelAnalytics function is actually being called.
  2. Check the response of the inetc::get call to MixPanel.

Do you know how to go about doing those two things? Can I echo the results to file somehow? (an example would be great, I'm really unfamiliar with NSIS)

If I can see what the MixPanel response is I should be fine to go ahead and modify the parameters to meet their needs. From what I can tell, the call already matches the requirements of their documentation.

@develar
Copy link
Member

develar commented Feb 10, 2017

Can I echo the results to file somehow? (an example would be great, I'm really unfamiliar with NSIS)

To debug you can use MessageBox MB_OK "debug message or $somevar"

@develar
Copy link
Member

develar commented Feb 10, 2017

See whether the MixPanelAnalytics function is actually being called.

I see that it is not correctly used in the script. result is not checked. To check result, in our scripts we use

    inetc::get /header "X-Arch: $packageArch" /RESUME "" "$packageUrl" "$PLUGINSDIR\package.7z" /END
    Pop $0
    ${if} $0 == "Cancelled"
      quit
    ${elseif} $0 != "OK"
      Messagebox MB_RETRYCANCEL|MB_ICONEXCLAMATION "Unable to download application package from $packageUrl (status: $0).$\r$\n$\r$\nPlease check you Internet connection and retry." IDRETRY download
      quit
    ${endif}

i.e. write result from stack to var $0 and then check it.

@sklink
Copy link
Author

sklink commented Feb 10, 2017

So I included a message box like this this:

!include "mp.nsh"

!macro customInstall
	Messagebox MB_OK "Processing" IDOK
	!insertmacro MixPanelAnalytics "701629741ac1ab59d98ce4f6f1cfbcd9" "Install"
!macroend
!macro customUnInstall
    ${GetParameters} $R0
    ${GetOptions} $R0 "--update" $R1
    ${IfNot} ${Errors}
			!insertmacro MixPanelAnalytics "701629741ac1ab59d98ce4f6f1cfbcd9" "Update"
		${Else}
			!insertmacro MixPanelAnalytics "701629741ac1ab59d98ce4f6f1cfbcd9" "Uninstall"
    ${endif}
!macroend

And nothing pops up during installation. So I assume that needs to be figured out before moving on to check MixPanel's return value (although I did add in the Messagebox for the MixPanel call as well.

@develar
Copy link
Member

develar commented Feb 10, 2017

I cannot check yet in code, but please try to move !include "mp.nsh" inside your macro

@sklink
Copy link
Author

sklink commented Feb 10, 2017

Same issue, no Messagebox. Trying with only installer.nsh in the build folder and this is the entirety of the contents:

!macro customInstall
	Messagebox MB_OK "Processing"
!macroend

The installer pops up with "Installing, Please Wait..." and the progress bar, but no Messagebox. Maybe there's something wrong with my package.json that's preventing installer.nsh from being included?

Here's the build section:

  "build": {
    "appId": "com.mycompany.myapp",
    "category": "public.app-category.tools",
    "asar": false,
    "productName": "MyApp",
    "dmg": {
      "contents": [
        {
          "x": 410,
          "y": 150,
          "type": "link",
          "path": "/Applications"
        },
        {
          "x": 130,
          "y": 150,
          "type": "file"
        }
      ]
    },
    "files": [
      "dist/",
      "node_modules/",
      "assets/",
      "state-processing/",
      "public/img/",
      "app.html",
      "main.js",
      "main.js.map",
      "package.json"
    ],
    "win": {
      "certificateSubjectName": "Company Inc.",
      "signingHashAlgorithms": "sha256",
      "rfc3161TimeStampServer": "http://timestamp.digicert.com"
    },
    "linux": {
      "target": [
        "deb",
        "AppImage"
      ]
    },
    "directories": {
      "buildResources": "resources",
      "output": "release"
    }
  }

@develar
Copy link
Member

develar commented Feb 10, 2017

I will check tomorrow CET.

@sklink
Copy link
Author

sklink commented Feb 10, 2017

Adding "nsis": { "include": "build/installer.nsh" } made the script run, I'm now getting build errors. Slowly working through then, will post when I'm stuck.

@sklink
Copy link
Author

sklink commented Feb 10, 2017

So I'm stuck now because when I do !include "mp.nsh", !include "build/mp.nsh", or !include "./mp.nsh". at the top of the file, the build fails with:

could not find: "mp.nsh"

the "mp.nsh" changes as I change the path.

Do I need to add the extra files to the "nsis": { "include": section?

@develar
Copy link
Member

develar commented Feb 11, 2017

#1239 (comment)

@sklink
Copy link
Author

sklink commented Feb 11, 2017

I was able to make progress but had to duplicate all of the macros with un. prefix to get it to work with the uninstaller method.

Has the same error as the person in #1239 where I had to turn off warningsAsErrors.

Right now I'm getting invalid json encoding back from MixPanel. I have been unable to include .dll plugins so I used this Base64: http://nsis.sourceforge.net/Base64. I may be able to continue to fiddle with it but being able to include a .dll to resolve the encoding would be great.

Will post back when I try again later tonight.

@sklink
Copy link
Author

sklink commented Feb 13, 2017

I managed to get this to work with the Base64 script. After doing some digging it turned out that MixPanelGuid was returning Chinese characters.

I ended up using a different method to create a GUID:

Function CreateGUID
  System::Call 'ole32::CoCreateGuid(g .s)'
FunctionEnd
!define CreateGUID `!insertmacro _CreateGUID`
!macro _CreateGUID _RetVar
    Call CreateGUID
    !if ${_RetVar} != s
        Pop ${_RetVar}
    !endif
!macroend

and used this CharStrip to get rid of the brackets and the dashes.

@sklink sklink closed this as completed Feb 13, 2017
@develar
Copy link
Member

develar commented Feb 13, 2017

@sklink include dir fixed in the 13.6.0

@develar
Copy link
Member

develar commented Feb 13, 2017

@sklink 13.6.0 allows you to disable Unicode (#1165 (comment)), so you can use dll from https://github.com/nmoinvaz/nsis-base64

@serg06
Copy link

serg06 commented Oct 17, 2021

Adding "nsis": { "include": "build/installer.nsh" } made the script run, I'm now getting build errors. Slowly working through then, will post when I'm stuck.

Thank you, this worked! Note to future people: nsis goes under build like this:

{
  "build": {
    "nsis": {
      "include": "build/installer.nsh"
    },
    ...
  },
  ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants