Install the right file with the same name depending on the app's language in NSIS

62 views Asked by At

The installer detects the language of the installed apps, let's say $detected_language will have a value of "pl".

Now I want that only one menu.cfg file is installed, based on the value of $detected_language. Using variables in File ... is not allowed. Is the only way to create lot of Sections, and name them "Kardaw Mod (English)", "Kardaw Mod (German)", etc., and hide all unnecessary Sections with flags which doesn't match the detected language? (menu.cfg cannot be modified on the fly, because it's encrypted).

var detected_language
...

!define MUI_PAGE_CUSTOMFUNCTION_LEAVE detect_app_language; /*$detected_language → "pl"*/
!insertmacro MUI_PAGE_DIRECTORY
...

Section "Kardaw Mod"
  SetOutPath "$INSTDIR\data"
  File "E:\MyMods\Kardaw Mod\English\data\menu.cfg"
  File "E:\MyMods\Kardaw Mod\German\data\menu.cfg"
  File "E:\MyMods\Kardaw Mod\French\data\menu.cfg"
  File "E:\MyMods\Kardaw Mod\Spanish\data\menu.cfg"
  File "E:\MyMods\Kardaw Mod\Russian\data\menu.cfg"
  File "E:\MyMods\Kardaw Mod\Polish\data\menu.cfg";/* ←this one is the correct one */
2

There are 2 answers

0
Kardaw On BEST ANSWER

First thought was to make these entries invisible in a group. But the - symbol was still visible, and the title of the section group had a greyed out checkmark ☑ if it was checked.

The solution for my question will be placing all the sections one by one. A function will check the right box when we leave the page. It will also check if the mod was selected.

Wrong Solution Right Solution

1
Slappy On

Create a variable holding the user selected language and use ${If}s to extract the desired file(s) only.

    Var /Global MySelectedlanguage ; Fill this variable with user selected language eg. "EN" for English etc.
    
    Section "Kardaw Mod"
      SetOutPath "$INSTDIR\data"

      ${If} $MySelectedlanguage == "EN"
      File "E:\MyMods\Kardaw Mod\English\data\menu.cfg"
      ${EndIf}

    ${If} $MySelectedlanguage == "DE"
      File "E:\MyMods\Kardaw Mod\German\data\menu.cfg"
    ${EndIf}

    ; ... The same for other languages ...
    SectionEnd