Download Latest

From NSIS Wiki
Jump to navigationJump to search
Author: Zinthose (talk, contrib)


Download Links

DownloadLatest.zip (47 KB)
Written and compiled using NSIS.

Description

Version 0.1

Download Latest is a compile time utility to download a file if it has changed from a web site and generate a NSIS header about the file for easy inclusion into your packages.

Forum Discussion

How To Use

Extract the exe to the "${NSISDIR}\Tools" path and use the !system command to execute it within your scripts.

Example

This example downloads the latest version of Adobe Flash x86 and includes it into the package.

OutFile "Setup[Adobe Flash x86].exe"
ShowInstDetails show
 
!system `"${NSISDIR}\Tools\DownloadLatest.exe" \
  /URL="http://download.macromedia.com/pub/flashplayer/curren/install_flash_player_ax_32bit.exe" \
  /DST="media\downloads" /NSH="Flash32"` = 0
!include "media\downloads\Flash32.nsh"
 
Section
    DetailPrint "File Version: ${DL_Flash32_Version}"
    DetailPrint "ETag: ${DL_Flash32_ETag}"
    DetailPrint "Last Modified: ${DL_Flash32_LastModified}"
    DetailPrint "FileName: ${DL_Flash32_FileName}"
    DetailPrint "Source Path: ${DL_Flash32_Path}"
 
    MessageBox MB_YESNO|MB_ICONQUESTION|MB_TOPMOST|MB_DEFBUTTON2 \
      "Do you want to install Adobe Flash?" /SD IDYES IDYes DoInstall
    Abort "User Aborted Install."
 
    DoInstall:
    InitPluginsDir
    SetOutPath $PLUGINSDIR\INST
    File "/oname=$OUTDIR\install.exe" "${DL_Flash32_Path}\${DL_Flash32_FileName}"
 
    StrCpy $0 ""
    IfSilent 0 +2
        StrCpy $0 "-install"
    ExecWait `"$OUTDIR\install.exe" $0` $0
    DetailPrint "Result: $0"
SectionEnd

Helper Macro

!define "!DownloadLatest" "!insertmacro _DownloadLatest"
!macro _DownloadLatest _URL _DST _NSH
    !verbose push
    !verbose 0
    !system `"${NSISDIR}\tools\DownloadLatest.exe" \
        /URL="${_URL}" \
        /DST="${_DST}" \
        /NSH="${_NSH}"` = 0
    !include "${_DST}\${_NSH}.nsh"
    !verbose pop
!macroend
 
${!DownloadLatest} \
    "http://download.macromedia.com/pub/flashplayer/current/install_flash_player_ax_32bit.exe" \
    "media\downloads" \
    "Flash32"

Versions History

0.1 - 02/Dec/2011
  • Initial release!

Credits

Author: Dane Jones (aka zinthose).

License

  This software is provided 'as-is', without any express or implied
  warranty. In no event will the authors be held liable for any damages
  arising from the use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute
  it freely, subject to the following restrictions

  1. The origin of this software must not be misrepresented;
     you must not claim that you wrote the original software.
     If you use this software in a product, an acknowledgment in the
     product documentation would be appreciated but is not required.
  2. Altered versions must be plainly marked as such,
     and must not be misrepresented as being the original software.
  3. This notice may not be removed or altered from any distribution.