如何在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 $INSTDIRdata
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

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

最新更新