在NSIS脚本中执行inetc::get下载前检测文件是否存在
在NSIS脚本中执行inetc::get下载前检测文件是否存在,可通过以下方式实现:使用IfFileExists指令
这是NSIS内置的经典文件检测方法,直接判断文件路径:
IfFileExists ".\test22222.exe" 0 +3
MessageBox MB_OK "文件已存在,跳过下载"
Goto skip_download
通过nsisXML插件检测
若需XML格式的检测结果:
nsisXML::create
nsisXML::load ".\test22222.exe"
Pop $0
StrCmp $0 "0" download_file
MessageBox MB_OK "文件已存在"
Goto skip_download
调用系统API(高级方法)
通过System::Call调用Windows API:
System::Call 'kernel32::GetFileAttributes(t ".\test22222.exe")i .r0'
IntCmp $0 0xFFFFFFFF download_file
MessageBox MB_OK "检测到文件已存在"
Goto skip_download
完整实现示例:
Section "Download Section"
IfFileExists ".\test22222.exe" 0 +3
MessageBox MB_OK "目标文件已存在,跳过下载"
Return
inetc::get ${PRODUCT_VC_REDIST_URL} ".\test22222.exe"
Pop $0
${If} $0 == "OK"
ExecWait '"$INSTDIR\test22222.exe" /quiet'
${Else}
MessageBox MB_ICONSTOP "下载失败: $0"
${EndIf}
SectionEnd
注意事项:
路径中的.\表示当前工作目录(通常是PLUGINSDIR或EXEDIR)
检测逻辑应放在下载操作前,避免重复下载
企业网络环境需考虑代理设置和认证问题
页:
[1]