问题描述
我正在使用 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
指令用于将文件压缩到安装程序中,并且只能在您编译安装程序的机器上使用。
使用 FileOpen
和 FileRead
解析用户系统上的文件。如果要将所选文件复制到安装目录,请使用 CopyFiles /silent /filesonly $LicenseFile $InstDir
。
在您的应用程序而不是安装程序中检查许可证可能是一个更好的主意...