Difference between revisions of "826 NSIS Install Script"

From Sensoray Technical Wiki
Jump to: navigation, search
(826 NSIS Install Script)
(826 NSIS Install Script)
 
(One intermediate revision by one user not shown)
Line 1: Line 1:
 
==826 NSIS Install Script==
 
==826 NSIS Install Script==
  
This script is provided as is. It is a possible starting point for users that wish to create their own installation script. Please note the file source links may not match the paths on one's own system.
+
This script is provided as-is. It is a possible starting point for users who wish to create their own installation script. Please note that the file source links may not match the paths on one's own system.
  
 
  ; s812.nsi
 
  ; s812.nsi
Line 476: Line 476:
 
   NoDelete:
 
   NoDelete:
 
  SectionEnd
 
  SectionEnd
 +
 +
[[Category:826|NSIS]]

Latest revision as of 11:06, 4 June 2020

[edit] 826 NSIS Install Script

This script is provided as-is. It is a possible starting point for users who wish to create their own installation script. Please note that the file source links may not match the paths on one's own system.

; s812.nsi
;

;--------------------------------

!ifdef HAVE_UPX
!packhdr tmp.dat "upx\upx -9 tmp.dat"
!endif

!ifdef NOCOMPRESS
SetCompress off
!endif
!include x64.nsh
!include winver.nsh
!include Library.nsh
!include FileFunc.nsh
;--------------------------------

Name "Sensoray826"
Caption "Sensoray 826 SDK   Version 3.3.9 (06/16/2016)"
Icon "sensoray.ico"
OutFile "..\cd\setup.exe"
; Request application privileges for Windows Vista
RequestExecutionLevel user
SetDateSave on
SetDatablockOptimize on
CRCCheck on
SilentInstall normal
BGGradient 000080 000000 FFFFFF
InstallColors 8080ff 000030
XPStyle on

InstallDir "$PROGRAMFILES\Sensoray\826"
InstallDirRegKey HKLM "Software\Sensoray\826" "Install_Dir"

CheckBitmap "${NSISDIR}\Contrib\Graphics\Checks\classic-cross.bmp"

LicenseText "Sensoray 826 License"
LicenseData "license.rtf"

RequestExecutionLevel admin

;--------------------------------

Page license
Page components


DirText "Setup will install S826 in the following folder.  If building apps, please not that Vista or Win7 UAC prevents building examples in the PROGRAMFILES directory as a regular user. You may want to choose a different default directory if you are a developer."


Page directory
Page instfiles

UninstPage uninstConfirm
UninstPage instfiles

;--------------------------------

!ifndef NOINSTTYPES ; only if not defined
  InstType "Most"
  InstType "Full"
!endif

AutoCloseWindow false
ShowInstDetails show

Function Slice
 Exch $R0 ; input string
 Exch
 Exch $R1 ; to cut
 Push $R2
 Push $R3
 Push $R4
 Push $R5
  
 StrLen $R3 $R1
 StrCpy $R4 -1
 StrCpy $R5 0
 
 Loop:
  
  IntOp $R4 $R4 + 1
  StrCpy $R2 $R0 $R3 $R4
  StrCmp $R2 "" Done
  StrCmp $R2 $R1 0 Loop
 
   StrCpy $R5 1
 
   StrCmp $R4 0 0 +3
    StrCpy $R1 ""
    Goto +2
   StrCpy $R1 $R0 $R4
   StrLen $R2 $R0
   IntOp $R4 $R2 - $R4
   IntOp $R4 $R4 - $R3
   IntCmp $R4 0 0 0 +3
    StrCpy $R2 ""
    Goto +2
   StrCpy $R2 $R0 "" -$R4
   StrCpy $R0 $R1$R2
  
 Done:
 StrCpy $R1 $R5
  
 Pop $R5
 Pop $R4
 Pop $R3
 Pop $R2
 Exch $R1 ; slice? 0/1
 Exch
 Exch $R0 ; output string
FunctionEnd


Function GetInQuotes
Exch $R0
Push $R1
Push $R2
Push $R3
 
 StrCpy $R2 -1
 IntOp $R2 $R2 + 1
  StrCpy $R3 $R0 1 $R2
  StrCmp $R3 "" 0 +3
   StrCpy $R0 ""
   Goto Done
  StrCmp $R3 '"' 0 -5
 
 IntOp $R2 $R2 + 1
 StrCpy $R0 $R0 "" $R2
  
 StrCpy $R2 0
 IntOp $R2 $R2 + 1
  StrCpy $R3 $R0 1 $R2
  StrCmp $R3 "" 0 +3
   StrCpy $R0 ""
   Goto Done
  StrCmp $R3 '"' 0 -5
 
 StrCpy $R0 $R0 $R2
 Done:
 
Pop $R3
Pop $R2
Pop $R1
Exch $R0
FunctionEnd


;--------------------------------
Var uninstallpath ; path_filename
Var uninstalldir  ;   just the directory
Section "" ; empty string makes it hidden, so would starting with -
   IfSilent NoOldVersion
   ClearErrors
    ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Sensoray826" "UninstallString"

    IfErrors NoOldVersion 0
    MessageBox MB_YESNO|MB_ICONQUESTION "Uninstall previous 826 SDK?" IDNO NoOldVersion
    DetailPrint "executing uninstall" 

    strcpy $uninstallpath $0
    Push "\uninstall.exe"
    Push $0
    call Slice
    Pop $R0
    Pop $R1
    strcpy $uninstalldir $R0
    push $R0
    call GetInQuotes
    Pop $R0

    ${If} $R1 == "1"
        ExecWait '$0 _?=$R0'
        ${If} $R1 == "1"
            push $uninstallpath
            call GetInQuotes
            pop $R0
            Delete $R0
            push $uninstalldir
            call GetInQuotes
            pop $R0
            RmDir $R0
        ${EndIf}
    ${Else}
        ExecWait '$0 _?=$INSTDIR'
        ; delete the installer (necessary because we don't use temp file 
        ; approach above
         
    RMDir "$INSTDIR" ; skipped if no

    ${EndIf}
NoOldVersion:
  ClearErrors
  ; write uninstall strings
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Sensoray826" "DisplayName" "Sensoray 826 SDK (remove only)"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Sensoray826" "UninstallString" '"$INSTDIR\uninstall.exe"'
  SetOutPath $INSTDIR
  WriteUninstaller "uninstall.exe"
  SetOutPath "$SYSDIR";
  SetOutPath "$WINDIR";
  SetOutPath "$INSTDIR";
  Nop
SectionEnd


Section "Core API"
  SectionIn RO
  CreateDirectory "$INSTDIR\API";
  SetOutPath "$INSTDIR\API";
  File "..\mid-826\code\826api.h";
  CreateDirectory "$INSTDIR\API\x32";
  SetOutPath "$INSTDIR\API\x32";
  File "..\cd\API\x32\readme_dll.txt";
  File "..\mid-826\code\Release\s826.lib";
  CreateDirectory "$INSTDIR\API\x64";
  SetOutPath "$INSTDIR\API\x64";
  File "..\cd\API\x64\readme_dll.txt";
  File "..\mid-826\code\Release64\s826.lib";

${If} ${RunningX64}
  SetOutPath "$WINDIR\system32";
!insertmacro  DisableX64FSRedirection
  File "..\mid-826\code\Release64\s826.dll";
!insertmacro  EnableX64FSRedirection
  SetOutPath "$WINDIR\SysWOW64";
  File "..\mid-826\code\Release\s826.dll";
${Else}
  SetOutPath "$WINDIR\system32";
  File "..\mid-826\code\Release\s826.dll";
${EndIf}

  SetOutPath "$INSTDIR\API";

;================begin VCredistributable installation===============
ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" "Install"
    IntCmp $0 1 done_dotnet install_dotnet
install_dotnet:
    DetailPrint "Installing dotnet 3.5"
    File "..\cd\ms_redist\dotnetfx35setup2.exe"
    ExecWait '"$INSTDIR\API\dotnetfx35setup2.exe" /qb'
done_dotnet:
    DetailPrint "Done dotnet 3.5"


  ;Check if VC++ 2008 runtimes are already installed:
    ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9A25302D-30C0-39D9-BD6F-21E6EC160475}" "DisplayName"
    StrCmp $0 "Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.17" done_vcredist vcredist_silent_install
  
  ;If VC++ 2008 runtimes are not installed...
  vcredist_silent_install:
    DetailPrint "Installing Microsoft Visual C++ 2008 Redistributable"
    File "..\cd\ms_redist\vcredist_x86.exe"
    ExecWait '"$INSTDIR\API\vcredist_x86.exe" /q' $0
    ;Check for successful installation of our vcredist_x86.exe...
    ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9A25302D-30C0-39D9-BD6F-21E6EC160475}" "DisplayName"
    StrCmp $0 "Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.17" vcredist_success vcredist_not_present
    vcredist_not_present:
      DetailPrint "Microsoft Visual C++ 2008 Redistributable failed to install"
      IfSilent done_vcredist vcredist_messagebox
      vcredist_messagebox:
;        MessageBox MB_OK "Microsoft Visual C++ 2008 Redistributable Package (x86) failed to install ($INSTDIR\vcredist_x86.exe). Please ensure your system meets the minimum requirements before running the installer again."
        Goto done_vcredist
    vcredist_success:
      Delete "$INSTDIR\vcredist_x86.exe" 
      DetailPrint "Microsoft Visual C++ 2008 Redistributable was successfully installed"
done_vcredist:
    ${If} ${RunningX64}
        File "..\cd\ms_redist\vcredist_x64.exe"
        ExecWait '"$INSTDIR\API\vcredist_x64.exe" /q' $0
    ${EndIf}

;================end VCredistributable installation===============

SectionEnd

Section "Drivers"
    ${GetParameters} $R0
    ${GetOptions} $R0 "/no_driver=" $R1
    ${If} $R1 == "1"
    GoTo NoInstallDriver
    ${Else}

    ${EndIf}

  SectionIn RO
  CreateDirectory "$INSTDIR\driver\x64";
  SetOutPath "$INSTDIR\driver\x64";
  File "..\cd\driver\x64\dpinst.exe";
  File "..\cd\driver\x64\s826.cat";
  File "..\cd\driver\x64\s826.inf";
  File "..\cd\driver\x64\s826.sys";
  File "..\cd\driver\x64\s826filter.cat";
  File "..\cd\driver\x64\s826filter.inf";
  File "..\cd\driver\x64\s826filter.sys";

  File "..\cd\driver\x64\WdfCoInstaller01009.dll";
  CreateDirectory "$INSTDIR\driver\x32";
  SetOutPath "$INSTDIR\driver\x32";
  File "..\cd\driver\x32\dpinst.exe";
  File "..\cd\driver\x32\s826.cat";
  File "..\cd\driver\x32\s826.inf";
  File "..\cd\driver\x32\s826.sys";
  File "..\cd\driver\x32\s826filter.cat";
  File "..\cd\driver\x32\s826filter.inf";
  File "..\cd\driver\x32\s826filter.sys";
  File "..\cd\driver\x32\WdfCoInstaller01009.dll";
#  MessageBox MB_YESNO|MB_ICONQUESTION "Update or pre-install driver(recommended) (YES/NO)?" IDNO NoInstallDriver
   IfSilent skip_popup
  MessageBox MB_OK "Driver installation dialog will pop-up. Follow the prompts and click Finish when done"
  skip_popup:
${If} ${IsWinXP}
  ${If} ${RunningX64}
    MessageBox MB_OK "XP 64-bit Windows version. Install drivers manually(try Vista64 driver)."
  ${Else}
      ExecWait '"$INSTDIR\driver\x32\dpinst.exe" /f'
  ${EndIf}
${ElseIf} ${IsWinVista}
  ${If} ${RunningX64}
  ExecWait '"$INSTDIR\driver\x64\dpinst.exe" /f'
  ${Else}
  ExecWait '"$INSTDIR\driver\x32\dpinst.exe" /f'
  ${EndIf}
${Else}
  ${If} ${RunningX64}
  ExecWait '"$INSTDIR\driver\x64\dpinst.exe" /f'
  ${Else}
  ExecWait '"$INSTDIR\driver\x32\dpinst.exe" /f'
  ${EndIf}
${EndIf}
NoInstallDriver:

SectionEnd

Section "Demo Apps"
    ${GetParameters} $R0
    ${GetOptions} $R0 "/no_demos=" $R1
    ${If} $R1 == "1"
    GoTo DemoAppEnd
    ${Else}

    ${EndIf}
  SectionIn RO
  CreateDirectory "$INSTDIR\demo";
  CreateDirectory "$INSTDIR\demo\bin";
  CreateDirectory "$INSTDIR\demo\bin\Release";
  CreateDirectory "$INSTDIR\demo\obj";
  CreateDirectory "$INSTDIR\demo\My Project";
  CreateDirectory "$INSTDIR\example_code";
  CreateDirectory "$INSTDIR\app-826-win-csharp";
  CreateDirectory "$INSTDIR\app-826-win-csharp\app-826-win-csharp";
  CreateDirectory "$INSTDIR\app-826-win-csharp\app-826-win-csharp\Properties";
  SetOutPath "$INSTDIR\demo";
  File "..\app-826-win-vb\project\app-826-win-vb\app-826-win-vb.sln"
  File "..\app-826-win-vb\project\app-826-win-vb\app-826-win-vb.vbproj"
  File "..\app-826-win-vb\project\app-826-win-vb\Counter.Designer.vb"
  File "..\app-826-win-vb\project\app-826-win-vb\Counter.vb"
  File "..\app-826-win-vb\project\app-826-win-vb\demo.ico"
  File "..\app-826-win-vb\project\app-826-win-vb\Form1.Designer.vb"
  File "..\app-826-win-vb\project\app-826-win-vb\Form1.vb"
  File "..\app-826-win-vb\project\app-826-win-vb\Main.Designer.vb"
  File "..\app-826-win-vb\project\app-826-win-vb\Main.resx"
  File "..\app-826-win-vb\project\app-826-win-vb\Main.vb"
  File "..\app-826-win-vb\project\app-826-win-vb\mid826.vb"
  SetOutPath "$INSTDIR\demo\My Project";
  File "..\app-826-win-vb\project\app-826-win-vb\My Project\Application.Designer.vb"
  File "..\app-826-win-vb\project\app-826-win-vb\My Project\Application.myapp"
  File "..\app-826-win-vb\project\app-826-win-vb\My Project\AssemblyInfo.vb"
  File "..\app-826-win-vb\project\app-826-win-vb\My Project\Resources.Designer.vb"
  File "..\app-826-win-vb\project\app-826-win-vb\My Project\Resources.resx"
  File "..\app-826-win-vb\project\app-826-win-vb\My Project\Settings.Designer.vb"
  File "..\app-826-win-vb\project\app-826-win-vb\My Project\Settings.settings"
  SetOutPath "$INSTDIR\demo\bin\Release";
  File "..\app-826-win-vb\project\app-826-win-vb\bin\Release\app-826-win-vb.exe"
  SetOutPath "$INSTDIR\example_code";
  File "..\mid-826\code\example\s826_example.c"
  SetOutPath "$INSTDIR\app-826-win-csharp";
  File "..\app-826-win-csharp\app-826-win-csharp.sln"
  SetOutPath "$INSTDIR\app-826-win-csharp\app-826-win-csharp";
  File "..\app-826-win-csharp\app-826-win-csharp\app-826-win-csharp.csproj"
  File "..\app-826-win-csharp\app-826-win-csharp\Form1.cs"
  File "..\app-826-win-csharp\app-826-win-csharp\Form1.Designer.cs"
  File "..\app-826-win-csharp\app-826-win-csharp\Form1.resx"
  File "..\app-826-win-csharp\app-826-win-csharp\mid826.cs"
  File "..\app-826-win-csharp\app-826-win-csharp\Program.cs"
  SetOutPath "$INSTDIR\app-826-win-csharp\app-826-win-csharp\Properties";
  File "..\app-826-win-csharp\app-826-win-csharp\Properties\AssemblyInfo.cs"
  File "..\app-826-win-csharp\app-826-win-csharp\Properties\Resources.Designer.cs"
  File "..\app-826-win-csharp\app-826-win-csharp\Properties\Resources.resx"
  File "..\app-826-win-csharp\app-826-win-csharp\Properties\Settings.Designer.cs"
  File "..\app-826-win-csharp\app-826-win-csharp\Properties\Settings.settings"
  goto DemoAppEnd

DemoAppEnd:
SectionEnd


Section "Start Menu Shortcuts"
  SectionIn 1 2
    ${GetParameters} $R0
    ${GetOptions} $R0 "/no_demos=" $R1
    ${If} $R1 == "1"
    GoTo ShortCutEnd
    ${Else}

    ${EndIf}

  Delete "$DESKTOP\826 Demo.lnk"
  CreateDirectory "$SMPROGRAMS\Sensoray\826"
  CreateShortCut "$SMPROGRAMS\Sensoray\826\826 Demo.lnk" "$INSTDIR\demo\bin\Release\app-826-win-vb.exe" "" "$INSTDIR\demo\bin\Release\app-826-win-vb.exe" 0 SW_SHOWNORMAL CONTROL|SHIFT|Q
  CreateShortCut "$SMPROGRAMS\Sensoray\826\826 VS2008.lnk" "$INSTDIR\demo\app-826-win-vb.sln" "" "$INSTDIR\demo\app-826-win-vb.sln" 0 SW_SHOWNORMAL CONTROL|SHIFT|Q
  CreateShortCut "$DESKTOP\826 Demo.lnk" "$INSTDIR\demo\bin\Release\app-826-win-vb.exe" "" "$INSTDIR\demo\bin\Release\app-826-win-vb.exe" 0 SW_SHOWNORMAL CONTROL|SHIFT|Q
  CreateShortCut "$SMPROGRAMS\Sensoray\826\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
ShortCutEnd:
SectionEnd


;--------------------------------
; Uninstaller
UninstallText "This will uninstall the Sensoray 826 SDK. Hit next to continue."
UninstallIcon "sensoray.ico"

Section "Uninstall"
  IfSilent NoDelete
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Sensoray826"
  DeleteRegKey HKLM "SOFTWARE\Sensoray\826"
  Delete "$INSTDIR\*.*"
  Delete "$INSTDIR\uninstall.exe"
  Delete "$SMPROGRAMS\Sensoray\826\*.*"
  RMDir "$SMPROGRAMS\Sensoray\826"
  Delete "$DESKTOP\826 Demo.lnk" 

  MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to remove the directory $INSTDIR?" IDNO NoDelete
    Delete "$INSTDIR\demo\My Project\*.*"
    Delete "$INSTDIR\demo\obj\Debug\*.*"
    Delete "$INSTDIR\demo\obj\Release\*.*"
    Delete "$INSTDIR\demo\obj\*.*"
    Delete "$INSTDIR\demo\bin\*.*"
    Delete "$INSTDIR\demo\bin\Release\*.*"
    Delete "$INSTDIR\demo\bin\Debug\*.*"
    Delete "$INSTDIR\demo\*.*"
    Delete "$INSTDIR\example_code\*.*"
    Delete "$INSTDIR\driver\x32\*.*"
    Delete "$INSTDIR\driver\x64\*.*"
    Delete "$INSTDIR\driver\*.*"
    Delete "$INSTDIR\API\x64\*.*"
    Delete "$INSTDIR\API\x32\*.*"
    Delete "$INSTDIR\API\*.*"
    RMDir "$INSTDIR\demo\My Project"
    RMDir "$INSTDIR\demo\obj\Debug"
    RMDir "$INSTDIR\demo\obj\Release"
    RMDir "$INSTDIR\demo\bin\Debug"
    RMDir "$INSTDIR\demo\bin\Release"
    RMDir "$INSTDIR\demo\obj"
    RMDir "$INSTDIR\demo\bin"
    RMDir "$INSTDIR\demo"
    RMDir "$INSTDIR\example_code"
    RMDir "$INSTDIR\API\x32"
    RMDir "$INSTDIR\API\x64"
    RMDir "$INSTDIR\API"
    RMDir "$INSTDIR\driver\x32"
    RMDir "$INSTDIR\driver\x64"
    RMDir "$INSTDIR\driver"
    Delete "$INSTDIR\*.*"
    Delete "$INSTDIR\uninstall.exe"
    RMDir "$INSTDIR\demo"
    RMDir "$INSTDIR" ; skipped if no
    DeleteRegKey  HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Sensoray826"
    IfFileExists "$INSTDIR" 0 NoErrorMsg
  NoErrorMsg:
  NoDelete:
SectionEnd
Personal tools
Namespaces

Variants
Actions
Toolbox