;NSIS Modern User Interface version 1.63
;Start Menu Folder Selection Example Script
;Written by Joost Verburg

!define MUI_PRODUCT "SharpPrivacy" ;Define your own software name here
!define MUI_VERSION "0.1" ;Define your own software version here

!include "MUI.nsh"

;--------------------------------
;Configuration

  ;General
  OutFile "SharpPrivacyInst.exe"

  ;Folder selection page
  InstallDir "$PROGRAMFILES\${MUI_PRODUCT}"
  
  ;Remember install folder
  InstallDirRegKey HKCU "Software\${MUI_PRODUCT}" ""
  
  ;$9 is being used to store the Start Menu Folder.
  ;Do not use this variable in your script (or Push/Pop it)!

  ;To change this variable, use MUI_STARTMENUPAGE_VARIABLE.
  ;Have a look at the Readme for info about other options (default folder,
  ;registry).

  ;Remember the Start Menu Folder
  !define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKCU" 
  !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\${MUI_PRODUCT}" 
  !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "SharpPrivacy"

  !define TEMP $R0
  
;--------------------------------
;Modern UI Configuration


  !define MUI_CUSTOMPAGECOMMANDS
  !define MUI_WELCOMEPAGE
  !define MUI_LICENSEPAGE
  !define MUI_DIRECTORYPAGE
  !define MUI_STARTMENUPAGE
  !define MUI_FINISHPAGE
    !define MUI_FINISHPAGE_RUN "$INSTDIR\SharpPrivacy.exe"  

  !define MUI_ABORTWARNING
  
  !define MUI_UNINSTALLER
  !define MUI_UNCONFIRMPAGE
  
;--------------------------------
;Languages
 
  !insertmacro MUI_LANGUAGE "English"
  
;--------------------------------
;Language Strings

  ;Description
  LangString DESC_SecCopyUI ${LANG_ENGLISH} "Copy SharpPrivacy to the application folder."
  BrandingText /TRIMRIGHT "SharpPrivacy Installer" 

;--------------------------------
;Data
  
  LicenseData "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\gpl.txt"

;--------------------------------
;Pages


  !insertmacro MUI_PAGECOMMAND_WELCOME
  !insertmacro MUI_PAGECOMMAND_LICENSE
  !define MUI_CUSTOMFUNCTION_LICENSE_PRE LicenseText
  Page license mui.LicensePre mui.LicenseShow mui.LicenseLeave "MUI_INSTALLBUTTON_LICENSE"

  !insertmacro MUI_PAGECOMMAND_DIRECTORY
  !insertmacro MUI_PAGECOMMAND_STARTMENU
  !insertmacro MUI_PAGECOMMAND_INSTFILES
  !insertmacro MUI_PAGECOMMAND_FINISH

;--------------------------------
;Installer Sections

Section "SharpPrivacy.exe" SecCopyUI

  Call IsDotNETInstalled
  Pop $R3
  StrCmp $R3 0 +3
    DetailPrint "Found .NET!"
    Goto +2
    ; else
    MessageBox MB_YESNO "Setup did not find the Microsoft .Net Framework installed. The Framework is nesseccary for SharpPrivacy to work at all. Are you sure you want to continue?" IDNo Quit

  ; write uninstall strings
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "DisplayName" "${MUI_PRODUCT}"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "UninstallString" '"$INSTDIR\uninstall.exe"'

  SetOutPath "$INSTDIR"
  SetCompress Auto
  SetOverwrite IfNewer
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\SynapticEffect.Forms.dll"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\ICSharpCode.SharpZipLib.dll"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\MagicLocalLibrary.dll"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\MenuImageLib.dll"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\OPaC.uxTheme.dll"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\OPaC.uxTheme.Win32.dll"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\SharpPrivacy.exe"
  SetOutPath $INSTDIR\images
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\about.rtf"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\about_logo.jpg"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\clipboard.bmp"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\clipboard.ico"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\copy.ico"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\currentwindow.bmp"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\currentwindow.ico"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\delete.ico"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\filesystem.ico"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\key.gif"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\Key.ico"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\keymanager.bmp"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\keymanager.ico"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\Logo.jpg"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\newkeypair.ico"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\paste.ico"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\SecretKey.ico"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\signature.ico"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\splash.bmp"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\trayicon.ico"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\userid.ico"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\working.bmp"
  File "C:\Dokumente und Einstellungen\df\Eigene Dateien\SharpPrivacy\Project\images\working.ico"
  SetOutPath "$INSTDIR"
  
  ;Store install folder
  WriteRegStr HKCU "Software\${MUI_PRODUCT}" "" $INSTDIR
  
  !insertmacro MUI_STARTMENU_WRITE_BEGIN
    
    ;Create shortcuts
    CreateDirectory "$SMPROGRAMS\${MUI_STARTMENUPAGE_VARIABLE}"
    CreateShortCut "$SMPROGRAMS\${MUI_STARTMENUPAGE_VARIABLE}\SharpPrivacy.lnk" "$INSTDIR\SharpPrivacy.exe" "" "$INSTDIR\IMAGES\trayicon.ico"
    CreateShortCut "$SMPROGRAMS\${MUI_STARTMENUPAGE_VARIABLE}\Uninstall.lnk" "$INSTDIR\UnInstall.exe"
    CreateShortCut "$SMSTARTUP\SharpPrivacy.lnk" "$INSTDIR\SharpPrivacy.exe" "" "$INSTDIR\IMAGES\trayicon.ico"
  
  !insertmacro MUI_STARTMENU_WRITE_END
  
  ;Create uninstaller
  WriteUninstaller "$INSTDIR\Uninstall.exe"

Quit:

SectionEnd

;Display the Finish header
;Insert this macro after the sections if you are not using a finish page
!insertmacro MUI_SECTIONS_FINISHHEADER

;--------------------------------
;Descriptions

!insertmacro MUI_FUNCTIONS_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecCopyUI} $(DESC_SecCopyUI)
!insertmacro MUI_FUNCTIONS_DESCRIPTION_END
 
;--------------------------------
;Uninstaller Section

Section "Uninstall"

  ;ADD YOUR OWN STUFF HERE!

  ;Delete Files
  Delete "$INSTDIR\SynapticEffect.Forms.dll"
  Delete "$INSTDIR\ICSharpCode.SharpZipLib.dll"
  Delete "$INSTDIR\MagicLibrary.dll"
  Delete "$INSTDIR\MagicLocalLibrary.dll"
  Delete "$INSTDIR\MenuImageLib.dll"
  Delete "$INSTDIR\OPaC.uxTheme.dll"
  Delete "$INSTDIR\OPaC.uxTheme.Win32.dll"
  Delete "$INSTDIR\SharpPrivacy.exe"
  Delete "$INSTDIR\IMAGES\about.rtf"
  Delete "$INSTDIR\IMAGES\about_logo.jpg"
  Delete "$INSTDIR\IMAGES\clipboard.bmp"
  Delete "$INSTDIR\IMAGES\clipboard.ico"
  Delete "$INSTDIR\IMAGES\copy.ico"
  Delete "$INSTDIR\IMAGES\currentwindow.bmp"
  Delete "$INSTDIR\IMAGES\currentwindow.ico"
  Delete "$INSTDIR\IMAGES\delete.ico"
  Delete "$INSTDIR\IMAGES\filesystem.ico"
  Delete "$INSTDIR\IMAGES\key.gif"
  Delete "$INSTDIR\IMAGES\Key.ico"
  Delete "$INSTDIR\IMAGES\keymanager.bmp"
  Delete "$INSTDIR\IMAGES\keymanager.ico"
  Delete "$INSTDIR\IMAGES\Logo.jpg"
  Delete "$INSTDIR\IMAGES\newkeypair.ico"
  Delete "$INSTDIR\IMAGES\paste.ico"
  Delete "$INSTDIR\IMAGES\SecretKey.ico"
  Delete "$INSTDIR\IMAGES\signature.ico"
  Delete "$INSTDIR\IMAGES\splash.bmp"
  Delete "$INSTDIR\IMAGES\trayicon.ico"
  Delete "$INSTDIR\IMAGES\userid.ico"
  Delete "$INSTDIR\IMAGES\working.bmp"
  Delete "$INSTDIR\IMAGES\working.ico"
  Delete "$INSTDIR\UnInstall.exe"
  
  ;Remove shortcut
  ReadRegStr ${TEMP} "${MUI_STARTMENUPAGE_REGISTRY_ROOT}" "${MUI_STARTMENUPAGE_REGISTRY_KEY}" "${MUI_STARTMENUPAGE_REGISTRY_VALUENAME}"
  
  StrCmp ${TEMP} "" noshortcuts
  
    Delete "$SMPROGRAMS\${TEMP}\SharpPrivacy.lnk"
    Delete "$SMPROGRAMS\${TEMP}\Uninstall.lnk"
    RMDir "$SMPROGRAMS\${TEMP}" ;Only if empty, so it won't delete other shortcuts
    
  noshortcuts:

  RMDir "$INSTDIR/images"
  RMDir "$INSTDIR"

  DeleteRegKey /ifempty HKCU "Software\${MUI_PRODUCT}"
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}"

  ;Display the Finish header
  !insertmacro MUI_UNFINISHHEADER

SectionEnd


Function LicenseText
  FindWindow $0 "#32770" "" $HWNDPARENT
  GetDlgItem $1 $0 102 #change
  SendMessage $1 ${WM_SETTEXT} 0 "STR:License Text$\r$\nLine 1$\r$\nLine 2$\r$\nLine 3" #change
FunctionEnd


; IsDotNETInstalled
;
; Usage:
;   Call IsDotNETInstalled
;   Pop $0
;   StrCmp $0 1 found.NETFramework no.NETFramework
Function IsDotNETInstalled
  Push $0
  Push $1
  Push $2
  Push $3
  Push $4

  ReadRegStr $4 HKEY_LOCAL_MACHINE \
    "Software\Microsoft\.NETFramework" "InstallRoot"
  # remove trailing back slash
  Push $4
  Exch $EXEDIR
  Exch $EXEDIR
  Pop $4
  # if the root directory doesn't exist .NET is not installed
  IfFileExists $4 0 noDotNET

  StrCpy $0 0

  EnumStart:

    EnumRegKey $2 HKEY_LOCAL_MACHINE \
      "Software\Microsoft\.NETFramework\Policy"  $0
    IntOp $0 $0 + 1
    StrCmp $2 "" noDotNET

    StrCpy $1 0

    EnumPolicy:

      EnumRegValue $3 HKEY_LOCAL_MACHINE \
        "Software\Microsoft\.NETFramework\Policy\$2" $1
      IntOp $1 $1 + 1
       StrCmp $3 "" EnumStart
        IfFileExists "$4\$2.$3" foundDotNET EnumPolicy

  noDotNET:
    StrCpy $0 0
    Goto done

  foundDotNET:
    StrCpy $0 1

  done:
    Pop $4
    Pop $3
    Pop $2
    Pop $1
    Exch $0
FunctionEnd

