NSIS Inetc 获取:我可以将下载的文件设为变量吗? [英] NSIS Inetc get: can I make the downloaded file a variable?
问题描述
当我在那里添加 File_1234.exe 时,代码正在运行.但是文件名改变了,download.php 重定向到了 exe.因此,不是在那里有固定的文件名,而是希望有一个不需要指定文件名的代码.
The code is working when I have File_1234.exe added there. But the file name changes and download.php redirects to the exe. So instead of having a fixed file name there, I would like to have a code where i don't need to specify file name.
是否可以用代码替换第一个 File_1234.exe 以下载 URL 给出的任何文件,从而用将运行(ExecShell)这个下载文件的代码替换第二个 File_1234.exe?谢谢
Is it possible to replace the first File_1234.exe with code to download whatever file the URL gives, and therefore to replace the second File_1234.exe with code that would run (ExecShell) this downloaded file?? Thanks
代码本身在这里:
Section "File"
inetc::get "http://example.com/download.php" "$pluginsdir\File_1234.exe"
Pop $0
DetailPrint "Result: $R0"
ExecShell "" '"$pluginsdir\File_1234.exe"'
SectionEnd
推荐答案
INetC 没有将 INTERNET_FLAG_NO_AUTO_REDIRECT 标志传递给 WinInet 的标志,因此无法在服务器返回 30x 时执行 head 请求并找到位置重定向代码.
INetC does not have a flag that passes the INTERNET_FLAG_NO_AUTO_REDIRECT flag to WinInet so there is no way to do a head request and find the location when the server returns a 30x redirection code.
如果您可以修改 download.php 以在存在特殊参数时将最终 URL 作为小文本文件返回,那么您可以发出两个 GET 请求,第一个获取名称,第二个执行主要下载:
If you can modify download.php to just return the final URL as a small text file when a special parameter is present then you can make two GET requests, the first to get the name and the second to do the main download:
Section
InitPluginsDir
StrCpy $0 "http://example.com/download.php?fileid=1234"
inetc::get /SILENT "$0&locationonly=1" "$PluginsDir\location.txt" /END
FileOpen $1 "$PluginsDir\location.txt" R
FileRead $1 $2
FileClose $1
StrLen $1 $2
loop:
IntOp $1 $1 - 1
StrCpy $3 $2 1 $1
StrCmp $3 '/' 0 +4
IntOp $1 $1 + 1
StrCpy $3 $2 "" $1
Goto +2
StrCmp $3 "" 0 loop
StrCmp $3 "" nofilename
inetc::get "$0" "$PluginsDir\$3" /END
Goto done
nofilename:
MessageBox mb_iconstop "Unable to parse filename from $2"
done:
SectionEnd
此示例假设 http://example.com/download.php?fileid=1234 会下载文件,但 http://example.com/download.php?fileid=1234&&locationonly=1 只会返回类似 http:///example.com/myfiles/whatever.exe
This example assumes that http://example.com/download.php?fileid=1234 would download the file but http://example.com/download.php?fileid=1234&&locationonly=1 would only return a URL like http://example.com/myfiles/whatever.exe
这篇关于NSIS Inetc 获取:我可以将下载的文件设为变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!