微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 NSIS 脚本中添加文件选择输入?

如何解决如何在 NSIS 脚本中添加文件选择输入?

我正在使用 NSIS 创建 Windows 安装程序。在此安装程序中,在一个页面上,我想请求用户使用许可文件输入添加许可文件。如果许可文件有效,则用户将能够继续,否则将抛出错误消息。但是在创建构建本身的过程中,我收到一个错误。请参考我的以下代码错误

Function LicenseWarning

  !insertmacro MUI_HEADER_TEXT "License Warning" ""
    nsDialogs::Create 1018
    Pop $LicenseWarningDialog

    ${If} $LicenseWarningDialog == error
        Abort
    ${EndIf}

    ${NSD_CreateLabel} 0 0 100% 20u "This version of QMF Vision requires license for activation. Ensure you have the license file available or contact your administrator."
    Pop $LicenseWarningMsg

  ${NSD_CreateGroupBox} 2u 70u 295u 38u "Select License File"
  ${NSD_CreateFileRequest} 10u 85u 210u 12u ""
  Pop $LicenseFileInput
  ${NSD_CreatebrowseButton} 228u 83u 55u 14u "browse..."
  Pop $browseButton
  ${NSD_OnClick} $browseButton OnbrowseForLicense
  ${NSD_SetText} $LicenseFileInput $LicenseFile

    nsDialogs::Show

FunctionEnd

Function OnbrowseForLicense

  nsDialogs::SelectFileDialog open "" "*.lic" 
  Pop $0

  ${If} $0 != ""
    ${GetFileName} $0 $1
    ${If} $1 == "license.lic"
      Strcpy $LicenseFile $0
      ${NSD_SetText} $LicenseFileInput $0
      SetoutPath $INSTDIR\data
      IfFileExists $LicenseFile 0 file_not_found
        File $LicenseFile  <= On this line I am getting an error
      file_not_found:
    ${Else}
      MessageBox MB_ICONinformatION|MB_OK "License file is invalid."
      Abort
    ${EndIf}
  ${EndIf}

FunctionEnd

错误

File: "$LicenseFile" -> no files found.
Usage: File [/nonfatal] [/a] ([/r] [/x filespec [...]] filespec [...] |
   /oname=outfile one_file_only)

请帮我解决。提前致谢。

解决方法

File 指令用于将文件压缩到安装程序中,并且只能在您编译安装程序的机器上使用。

使用 FileOpenFileRead 解析用户系统上的文件。如果要将所选文件复制到安装目录,请使用 CopyFiles /silent /filesonly $LicenseFile $InstDir

在您的应用程序而不是安装程序中检查许可证可能是一个更好的主意...

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。