equinor / witsml-explorer

Witsml Explorer data management tool.
Apache License 2.0
45 stars 50 forks source link

Set API port manually during installation #2363

Open janmarius opened 4 months ago

janmarius commented 4 months ago

Currently, the API port is set with a hard-coded value during the installation process. If you need to change the port, you will have to configure it in the config file located in AppData.

To improve the user experience, we want to enable users to set a port for the API during installation. This will allow users to manually set a different port if needed.

Good starting point: https://github.com/equinor/witsml-explorer/blob/43a2bae2ca9983e17e83c4c5a33bf625658e1f19/Src/WitsmlExplorer.Desktop/src/main/main.ts#L26

eliasbruvik commented 4 months ago

To add custom pages to the nsis installation, we need to provide a custom nsis script. I tried creating a script, but could not get it to work. I successfully added a page to the existing installer, but it failed when trying to use nsJSON to create the json file.

These are the main steps of my attempts:

Add this to the nsis part of electron-builder.json: "include": "installerAppConfig.nsi",

Create file installerAppConfig.nsi:

!include "nsDialogs.nsh"
!include "MUI2.nsh"

Var Dialog
Var DbPathInput
Var ApiPortInput
Var LogsPathInput
Var JsonHandle

Page custom ConfigPageCreate ConfigPageLeave
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

Function ConfigPageCreate
    nsDialogs::Create 1018
    Pop $Dialog

    ${NSD_CreateLabel} 0 10u 100% 12u "Database Path:"
    ${NSD_CreateText} 0 25u 100% 12u "" $DbPathInput

    ${NSD_CreateLabel} 0 50u 100% 12u "API Port:"
    ${NSD_CreateText} 0 65u 100% 12u "" $ApiPortInput

    ${NSD_CreateLabel} 0 90u 100% 12u "Logs Path:"
    ${NSD_CreateText} 0 105u 100% 12u "" $LogsPathInput

    nsDialogs::Show
FunctionEnd

Function ConfigPageLeave
    ${NSD_GetText} $DbPathInput $0
    ${NSD_GetText} $ApiPortInput $1
    ${NSD_GetText} $LogsPathInput $2

    ${nsJSON::Create} $JsonHandle
    ${nsJSON::Set} $JsonHandle "$.\"dbPath\"" $0
    ${nsJSON::Set} $JsonHandle "$.\"apiPort\"" $1
    ${nsJSON::Set} $JsonHandle "$.\"logsPath\"" $2

    ${nsJSON::Serialize} $JsonHandle $0
    ${If} $0 == error
        MessageBox MB_OK "Failed to serialize JSON!"
        Abort
    ${EndIf}

    FileOpen $1 "$INSTDIR\config.json" w
    FileWrite $1 $0
    FileClose $1

    ${nsJSON::Delete} $JsonHandle
FunctionEnd

Section
SectionEnd

Download the nsJSON plugin from https://nsis.sourceforge.io/NsJSON_plug-in, and copy the arch folders with .dll files to WitsmlExplorer.Desktop/resources

I also tried to place the .dll files along with the default plugins in electron-builder's nsis cache in appData. I also placed them in a different folder and referenced them with !addplugindir /x86-unicode ${PROJECT_DIR}\plugins\x86-unicode or !addplugindir ${PROJECT_DIR}\plugins in installerAppConfig.nsi.

No matter what I tried, I always got a "plugin not found" error. image

The error occurs even though I can see that the correct folder is logged as a plugin directory. image