Skip to content

Commit

Permalink
installer/sdk.nsi: Made it choose the installation directory in a muc…
Browse files Browse the repository at this point in the history
…h better way. It now chooses it before displaying it to the user, and complains if the user changes it to a directory that already exists.
  • Loading branch information
DavidEGrayson committed Feb 14, 2012
1 parent 64b5e2d commit 442786a
Showing 1 changed file with 37 additions and 25 deletions.
62 changes: 37 additions & 25 deletions installer/sdk.nsi
Expand Up @@ -2,40 +2,52 @@

!define SDK_VER "120127"

!define STARTDIR ".\build\wixel-sdk\"
OutFile ".\build\pololu-wixel-sdk-${SDK_VER}.exe"
OutFile "build\pololu-wixel-sdk-${SDK_VER}.exe"

!include LogicLib.nsh
!include FileFunc.nsh

SetCompressor /solid lzma
RequestExecutionLevel admin
InstallDir "C:\wixel-sdk\"
Name "Wixel SDK ${SDK_VER}"
ShowInstDetails show
ShowUninstDetails show
AllowSkipFiles on
Page directory
Page directory "" "" checkDirectory
Page instfiles

!macro TryInstDir path
StrCpy $INSTDIR "${path}"
${unless} ${FileExists} $INSTDIR
Return
${endif}
!macroend

Function .onInit
# Choose an appropriate installation directory that does not already exist.
!insertmacro TryInstDir "C:\wixel-sdk"
!insertmacro TryInstDir "C:\wixel-sdk-${SDK_VER}"
StrCpy $0 "2"
${do}
!insertmacro TryInstDir "C:\wixel-sdk-${SDK_VER}-$0"
IntOp $0 $0 + 1
${loop}
FunctionEnd

Function checkDirectory
# Make sure the user didn't choose a directory that already exists, because that
# could wipe out his previous changes to the SDK and leave him with an
# inconsistent set of SDK files.
${if} ${FileExists} $INSTDIR
MessageBox MB_OK|MB_ICONSTOP "The folder $INSTDIR already exists. To avoid overwriting previous work, please choose a different folder that does not already exist."
Abort
${endif}
FunctionEnd

Section "Main"
Call SDKExists
SetOutPath $INSTDIR
File /r "${STARTDIR}"
DetailPrint "PLEASE NOTE: This is NOT the latest version of the Wixel SDK."
DetailPrint "For the latest version with all the latest apps and libraries,"
DetailPrint "go to: https://github.com/pololu/wixel-sdk"
SectionEnd

Function SDKExists
${if} ${FileExists} $INSTDIR
StrCpy $8 "$INSTDIR"
StrCpy $INSTDIR "$INSTDIR-${SDK_VER}"
MessageBox MB_OK "The installation folder $8 already exists. To avoid conflicts, the new Wixel SDK files will be installed to: $INSTDIR"
${andif} ${FileExists} $INSTDIR
${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
StrCpy $8 "$INSTDIR"
StrCpy $INSTDIR "$INSTDIR-$2$1$0$4$5$6"
MessageBox MB_OK "The installation folder $8 already exists. To avoid conflicts, the new Wixel SDK files will be installed to: $INSTDIR"
${EndIF}
FunctionEnd
SetOutPath $INSTDIR
File /r "build\wixel-sdk"
# TODO: put this note in a better place (e.g. use nsDialogs to put it on its own page)
DetailPrint "PLEASE NOTE: This is NOT the latest version of the Wixel SDK."
DetailPrint "For the latest version with all the latest apps and libraries,"
DetailPrint "go to: https://github.com/pololu/wixel-sdk"
SectionEnd

0 comments on commit 442786a

Please sign in to comment.