electron NSIS:如何根据所选语言加载不同的许可证文件

tvokkenx  于 2023-03-06  发布在  Electron
关注(0)|答案(1)|浏览(264)

我试图使一个NSIS安装程序与电子建设者。我需要显示不同的许可证文件所选择的语言为基础的用户。

  • 包. json *
"devDependencies": {
    "electron": "22.0.1",
    "electron-builder": "^23.6.0"
  },

"build": {
    
    "directories": {
      "output": "out"
    },

    "win": {
      "target": "nsis",
      "icon": "images/logo.ico"
    },

    "nsis": {
      "oneClick": false,
      "deleteAppDataOnUninstall": true,
      "uninstallerIcon": "images/logo.ico",
      "installerIcon": "images/logo.ico",

      "displayLanguageSelector": true,
      "installerLanguages": ["en_US", "bg_BG"],
      "multiLanguageInstaller": true,

      "perMachine": true,
      "include": "build/preInstall.nsh"
    }
  }
}
  • 预安装. nsh *
!include MUI2.nsh
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE $(translatedlicensefile)
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_LANGUAGE English
LicenseLangString translatedlicensefile ${LANG_ENGLISH} "build/license/license_en.txt"
!insertmacro MUI_LANGUAGE Bulgarian
LicenseLangString translatedlicensefile ${LANG_BULGARIAN} "build/license/license_bg.txt"

得到这个错误:

Error output:
LicenseLangString: open failed "build/license/license_en.txt"
Usage: LicenseLangString name lang_id|0 license_path
!include: error in script: "/Users/..../preInstall.nsh" on line 32
Error in script "<stdin>" on line 51 -- aborting creation process

第32行

LicenseLangString translatedlicensefile ${LANG_ENGLISH} "build/license/license_en.txt"

我尝试了许多例子,包括官方的一个,并认为使用电子建设者搞砸了NSIS脚本的流程,我不能包括在这一点上的任何修改。
先谢了。

icnyk63a

icnyk63a1#

我找到了将许可证文件直接加载到NSIS代码中的解决方法。这不是很好的做法,但仍在寻找更好的解决方案。

  • 节点模块/应用程序构建器-库/输出/目标/nsis/nsisLicense.js*
const licenseFiles = await license_1.getLicenseFiles(packager);
// --> workaround
let license_bg = {file: packager.projectDir + "/pages/license_bg.txt", lang:"bg", langWithRegion:"bg_BG", langName:"Bulgarian"};
let license_en = {file: packager.projectDir + "/pages/license_en.txt", lang:"en", langWithRegion:"en_US", langName:"English"};
licenseFiles.push(license_el);
licenseFiles.push(license_en);
// <-- workaround
// if (licenseFiles.length === 0) {
//     return;
// }

相关问题