NSIS Inetc get: can I make the downloaded file a variable?

百般思念 提交于 2021-01-28 12:10:26

问题


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.

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

The code itself is here:

Section "File"
inetc::get "http://example.com/download.php" "$pluginsdir\File_1234.exe"
Pop $0
DetailPrint "Result: $R0"
    ExecShell "" '"$pluginsdir\File_1234.exe"'
SectionEnd

回答1:


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.

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

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




回答2:


This is possible if your "http://example.com/download.php" returns URL of file to download. What I mean: download.php returns URL as text ("http://example.com/file_12345.exe").

1) This text is downloaded with inetc to some local file and read into variable. 2) Use Inetc to download the file from URL (specified in variable) again as a resulting .exe file.

Is this acceptable for you?




回答3:


This is a 5 year later answer to help who ever might want to know how to get inetc::get output into a variable ;) Obviously you found a solution since then... anyway:

inetc::get has a nice option /TOSTACK that does this.

Here's how on your example:

!include LogicLib.nsh

Section "File"
inetc::get /TOSTACK "http://example.com/download.php" ""
Pop $0
DetailPrint "Result: $0"
${If} $0 == 'OK'
    Pop $0
    StrCpy $filename $0 
    inetc::get /TOSTACK "http://example.com/$filename" "$PluginsDir\$filename"
    Pop $0
    ${If} $0 == 'OK'
        ExecShell "" '"$pluginsdir\$filename"'
    ${Else}
        MessageBox MB_OK "Cannot download file $filename"
    ${EndIf}
${Else}
    MessageBox MB_OK "Cannot fetch filename to download"
${EndIf}

SectionEnd



来源:https://stackoverflow.com/questions/33647630/nsis-inetc-get-can-i-make-the-downloaded-file-a-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!