; Tom’s Image Gallery 2.1 Setup Script (TN)
; Written by Tom Nowacki @ https://www.teanow5pm.co.uk
;
; Requires NSIS >= 3.0a0
;--------------------------------

; Installer Definitions

!define PRODUCT_NAME "TIG"
!define PRODUCT_VERSION "2.1"
!define PRODUCT_PUBLISHER "CAGD"
!define PRODUCT_COPYRIGHT "© 2018 Tom Nowacki (CAGD)"
!define PRODUCT_WEB_SITE "https://www.teanow5pm.co.uk"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define APP_DATA_KEY "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
!define HELP_KEY "chm.file\shell\open\command"
!define CHM_KEY ".chm"
!define HELP_ROOT_KEY "HKCR"
!define LOCAL "..\" ; Path where local include files reside
!define ABSDIR "F:\homepage\nsis" ; Absolute local include path
!define SRCDIR "F:\Gallery"
!define TEMP $INSTDIR\bin ; Temporary location of encrypted archives
!define TEMP1 $R0 ; Temp variable
!define TEMP2 $R1 ; Temp variable
!define MESSAGE_INST_LANG_INFO $0 ; Language dialog text
!define X 0 ; write/read uninstall strings (self-uninstall option)
; (0 - all Windows versions | 5 - Vista+ | > 6 - do not write strings)
; Uncomment the next line for testing the installer
#!define MUI_QUICK_COMPILE
; Unicode NSIS
; Uncomment the next line for unicode
#Unicode true ; NSIS_UNICODE is not defined until you use the "Unicode true" attribute
!ifdef NSIS_UNICODE
  !define UNICODE
!endif
!ifdef UNICODE
  !define inst "TIGsetup-unicode_"
  !define instx "TIGsetup-unicode.exe"
  !define uninst "uun-TIGsetup_"
  !define uninstx "uuninst.exe"
  !define SEX "Size\setsizew.nsi"
  !define NSIDIR "UNICODE"
!else
  !define inst "TIGsetup_"
  !define instx "TIGsetup.exe"
  !define uninst "un-TIGsetup_"
  !define uninstx "uninst.exe"
  !define SEX "Size\setsize.nsi"
  !define NSIDIR "ANSI"
  !delfile $%TEMP%\nst*.tmp ; old copies
!endif
; Uncomment the next line to compile an uninstaller with welcome & finish pages
!define MUI_UN_FULL
; Uncomment the next line to skip the reinstall and directory pages
#!define MUI_AUTO_SKIP
; Uncomment the next line to run 'Banner.dll' (plug-in) for uninstalling from the prep page
#!define MUI_UN_RUN "false"
!ifndef MUI_UN_RUN
  !define MUI_UN_RUN "true"
!else
  !define MUI_UN_BANNER
!endif
; Comment out the next line to disable the password page
!define PASS_ON
; Uncomment the next line to put the temp install folder in localappdata (xp sp2+)
#!define PLUGINSDIR_APPDATA
; Uncomment the next line to prompt when files can't be overwritten
!define OVERWRITE_ON
!ifndef OVERWRITE_ON
  SetOverwrite try ; skip files that are locked
!else
  SetOverwrite on ; overwrite existing
  AllowSkipFiles on ; 'abort/retry/ignore' message
!endif
; Uncomment the next line to allow root install paths
!define ALLOW_ROOT
!ifdef ALLOW_ROOT
  AllowRootDirInstall true
!endif
; Uncomment the next line to use modified MUI language files
#!define MUI_MODIFIED
#!system '"${NSISDIR}\makensis.exe" "${LOCAL}${SEX}"' ; output "setsize.exe"
!execute "setsize.exe /S" ; generate "setsize.nsh"
#!delfile "setsize.exe" ; remove "setsize.exe"
!include "setsize.nsh" ; generated file
; Uncomment the next line to add Windows OSes to the installer/uninstaller manifests (manually)
#!define MANIFEST
!ifdef MANIFEST
  !define ResHacker "${ABSDIR}\Resource Hacker\ResourceHacker.exe" ; external tool
  !tempfile tmpexe
  !tempfile tmpmanifest
  !define level "asInvoker" ; = 'RequestExecutionLevel user'
  !define build ${NSIS_VERSION}
  !appendfile ${tmpmanifest} '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">\
<assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="Nullsoft.NSIS.exehead" type="win32"/>\
<description>Nullsoft Install System "${build}"</description>\
<dependency><dependentAssembly>\
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" \
processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>\
</dependentAssembly></dependency>\
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">\
<security><requestedPrivileges><requestedExecutionLevel level="${level}" uiAccess="false"/></requestedPrivileges></security>\
</trustInfo>\
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"><application>\
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>\
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>\
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>\
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>\
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>\
</application></compatibility>\
<application xmlns="urn:schemas-microsoft-com:asm.v3"><windowsSettings>\
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>\
</windowsSettings></application>\
</assembly>'
  !packhdr "${tmpexe}" '"${ResHacker}" -addoverwrite "${tmpexe}", "${tmpexe}", "${tmpmanifest}", 24, 1, 1033'
  !delfile "${tmpexe}"
!endif
; Uncomment the next line to add header compression (small amount)
!define upx "${ABSDIR}\UPX\upx.exe" ; external tool
!ifdef upx
  !tempfile tmpupx
  !packhdr "${tmpupx}" '"${upx}" -9 "${tmpupx}"'
!endif

;--------------------------------
; MUI 2.0 ------
!ifndef MUI_MODIFIED
  !include "MUI2.nsh"
  !define MUI_LICENSEPAGE_TEXT_TOP "$(M_INNERTEXT_LICENSE_BOTTOM_CHECKBOX)"
!else
  !include "${LOCAL}Modern UI 2\MUI2.nsh" ; modified (local)
  !define MUI_LICENSEPAGE_TEXT_TOP "$(MUI_INNERTEXT_LICENSE_BOTTOM_CHECKBOX)"
!endif
; Detect OS ------
!include "WinVer.nsh"
!include "x64.nsh"
; Custom functions ------
!include "TIGmacros.nsh"

; Configuration
!ifndef MANIFEST
  RequestExecutionLevel user
  ManifestSupportedOS all
!endif
ManifestDPIAware true ; application is not scaled by the DWM
Caption "${PRODUCT_NAME} Setup"
Name "${PRODUCT_NAME}"
BrandingText "${PRODUCT_COPYRIGHT}"
OutFile "${LOCAL}${instx}"
ShowInstDetails hide
ShowUninstDetails hide
AutoCloseWindow true
XPStyle on
SetCompress auto ; default - compress if smaller
!ifndef PASS_ON
  SetCompressor /SOLID /FINAL lzma
!else
  SetCompressor zlib
!endif

; Variables
Var APP_DATA      ; application data directory (when $APPDATA is unavailable)
Var HELP          ; path of Help application
Var DESK          ; desktop icon
Var ACCOUNT       ; admin or user
Var LANG          ; previous installer's language (registry)
Var LANG_ID       ; user's system language
Var PATH          ; previous $INSTDIR (registry)
Var ICONS_PATH    ; previous start menu folder (registry)
Var ICONS_GROUP   ; start menu folder
Var PAR_NUM       ; number of parent folders installed (registry) - these can be uninstalled, if empty
Var PREV_INST     ; copy exists
Var PREV_INST_V   ; type & number of copies
Var CU_PREV_INST  ; personal copy (user)
Var LM_PREV_INST  ; per-machine copy (all users)
Var REM           ; remove copy
Var WIN_V         ; Windows version
Var SYS_DIR       ; System folder
Var SYS__DIR      ; 64-bit system folder
Var UNINSTSTR     ; uninstall string (registry)
Var UNINST        ; path of removed copy
Var DTI           ; desktop icon caption text (T I G or T.I.G.) - T.I.G. is for admin copies
Var SPAWN         ; uninstall commandline option
Var PASSWORD      ; used to store the password
Var DIALOG        ; nsDialogs control
Var IMAGECTL      ; nsDialogs control
Var IMAGE         ; nsDialogs handle
Var CHECKBOX_1    ; nsDialogs control
Var CHECKBOX_2    ; nsDialogs control
Var CHECK_STATE   ; checked or unchecked
Var RADIO_1       ; nsDialogs control
Var RADIO_2       ; nsDialogs control
Var RADIO_STATE   ; checked or unchecked
Var MY_PROFILE    ; username
Var X_PROFILE     ; previous username
Var X_ACCOUNT     ; previous account (registry)
Var TIME          ; timestamp
Var X             ; delete registry and desktop icon
Var SIZE          ; required space (setsize.nsh)
Var SIZE_1        ; equal to SIZE
Var SIZE_2        ; alternate SIZE (C:\Gallery) - pdfs using absolute path links
Var BYTE_SIZE     ; original size (setsize.nsh)

;--------------------------------
; Page Macros

!macro PAGE_WELCOME
  Page custom nsDialogsWelcome ""
!macroend

!macro PAGE_PASS
  Page custom nsDialogsPasswordPage PasswordPageLeave ""
!macroend

!macro PAGE_PREP
  Page custom nsDialogsReinstallPage ReinstallPageLeave ""
!macroend

!macro PAGE_READY
  Page custom nsDialogsPreinstallPage PreinstallPageLeave ""
!macroend

!macro PAGE_FINISH
  Page custom nsDialogsFinish post_install ""
!macroend

;--------------------------------
; SFX Extraction

!macro overwrite_error file
  !ifdef OVERWRITE_ON ; prompt user what to do
      StrCpy $0 "$OUTDIR\${file}" #
    MessageBox MB_ICONSTOP|MB_ABORTRETRYIGNORE|MB_DEFBUTTON1 "$(^FileError)" /SD IDIGNORE IDABORT +3 IDRETRY +4
      StrCpy $0 "ignore" #
    Goto +3
    Abort
      StrCpy $0 "retry" #
  !else
      StrCpy $0 "ignore" #
  !endif
!macroend

!define x_x "!insertmacro extract_exe"

!macro extract_exe folder exe
  ; exe = self-extracting archive
  SetOutPath ${TEMP}
  File "${SRCDIR}${folder}\${exe}"
!macroend

!macro extract_berliner exe
  ; exe = "htmlexev.exe" or "htmlexe.exe"
  SetOutPath "-"
  retry__${exe}:
  nsExec::Exec '"${TEMP}\${exe}" -y -p${PW} -o"$OUTDIR"'
  Pop $0
  ; 7-Zip exit codes:
  ; 0 = No error > continue
  ; 1 = Non-fatal > continue
  ; 2 = Fatal, for example, if the file is locked > skip or prompt
  ; 7 = Command line error > skip or prompt
  ; 8 = Not enough memory for operation > skip or prompt
  ; 255 = User stopped the process > not applicable
  IntCmp $0 2 0 +4 0
  !insertmacro overwrite_error berliner.exe
  StrCmp $0 "retry" retry__${exe}
  StrCmp $0 "ignore" +3
  DetailPrint "$(^Extract)berliner.exe"
  Goto +2
  DetailPrint "$(^Skipped)berliner.exe"
  Delete "${TEMP}\${exe}"
  Sleep 5
!macroend

!define x_f "!insertmacro extract_files"

!macro extract_files folder exe
  ; folder = 'htm' or 'pdf'
  ; exe = "html.exe" or "pdf.exe"
  nsExec::Exec '"${TEMP}\${exe}" -y -p${PW} -o"${TEMP}\${folder}"'
  Pop $0
  StrCmp $0 "0" 0 +2
  DetailPrint "$(^Extract)${TEMP}\${folder}"
  Delete "${TEMP}\${exe}"
!macroend

!define copy_temp_pdf "!insertmacro copy_temp pdf ${outdir}"
!define copy_temp_htm "!insertmacro copy_temp htm 0" ; 0 = no outdir

!macro copy_temp folder outdir file
  ; outdir identifies the install folder, acro+'ice' or acro+'home'
  IfFileExists "${TEMP}\${folder}\${file}" +3
  DetailPrint "$(DETAIL_NOT_FOUND)${TEMP}\${folder}\${file}"
  Goto end__${outdir}__${file}
  ClearErrors
  IfFileExists "$OUTDIR\${file}" retry__${outdir}__${file}
  System::Call 'kernel32::MoveFile(t "${TEMP}\${folder}\${file}", t "$OUTDIR\${file}", i 0)i.r0'
  StrCmp $0 "0" 0 success__${outdir}__${file}
  retry__${outdir}__${file}:
  ClearErrors
  System::Call 'kernel32::CopyFile(t "${TEMP}\${folder}\${file}", t "$OUTDIR\${file}", i 0)i.r0'
  StrCmp $0 "0" 0 success__${outdir}__${file}
  !insertmacro overwrite_error ${file}
  StrCmp $0 "retry" retry__${outdir}__${file}
  StrCmp $0 "ignore" fail__${outdir}__${file}
  success__${outdir}__${file}:
  DetailPrint $(^CopyTo)${file}
  Goto end__${outdir}__${file}
  fail__${outdir}__${file}:
  DetailPrint "$(^CopyFailed): ${file}"
  end__${outdir}__${file}:
  Sleep 5
!macroend

!macro copy_omail i j
  ; j = number of files
  ; i = base name ('text' or 'add')
  ; loop through "text*.htm" or "add*.htm" or mo_a*.htm or mo_t*.htm
  IntOp $R0 1000 - ${j}
  ${i}__loop:
  IntCmp $R0 999 0 0 ${i}__done
  IntOp $R1 ${j} + $R0
  StrCpy $R1 $R1 "" -3 #
  ${copy_temp_htm} "${i}$R1.htm"
  IntOp $R0 $R0 + 1
  Goto ${i}__loop
  ${i}__done:
!macroend

!macro copy_pdf outdir
#  ${copy_temp_pdf} "exhibita.pdf"
#  ${copy_temp_pdf} "exhibit.pdf"
#  ${copy_temp_pdf} "gent.pdf"
#  ${copy_temp_pdf} "genta.pdf"
#  ${copy_temp_pdf} "guide.pdf"
#  ${copy_temp_pdf} "guidea.pdf"
#  ${copy_temp_pdf} "impo.pdf"
#  ${copy_temp_pdf} "impoa.pdf"
#  ${copy_temp_pdf} "magic.pdf"
#  ${copy_temp_pdf} "magica.pdf"
  ${copy_temp_pdf} "mo.pdf"
#  ${copy_temp_pdf} "quotes.pdf"
#  ${copy_temp_pdf} "quotesa.pdf"
#  ${copy_temp_pdf} "voyeur.pdf"
#  ${copy_temp_pdf} "voyeura.pdf"
!macroend

!macro copy_htm
  SetOutPath "-"
  !insertmacro copy_omail add ${A_0}
  !insertmacro copy_omail text ${T_0}
  !insertmacro copy_omail mo_a ${A_1}
  !insertmacro copy_omail mo_t ${T_1}
  ; copy remaining
  ${copy_temp_htm} "exhibit.htm"
  ${copy_temp_htm} "gent.htm"
  ${copy_temp_htm} "impo.htm"
  ${copy_temp_htm} "magic.htm"
  ${copy_temp_htm} "quotes.htm"
  ${copy_temp_htm} "voyeur.htm"
  SetDetailsPrint textonly
  RMDir /r ${TEMP}\htm
  Sleep 5
  SetDetailsPrint both
!macroend

!macro copy_icehome outdir
  ; outdir = 'ice' or 'home'
  SetOutPath "$INSTDIR\acro${outdir}"
  !insertmacro copy_pdf ${outdir}
  SetDetailsPrint textonly
  RMDir /r ${TEMP}\pdf
  Sleep 5
  SetDetailsPrint both
!macroend

;--------------------------------
; Install Macros

!macro quick_compile
  SetOutPath "-"
  File "${SRCDIR}\index.hta"
!macroend

!macro file_gallery
  SetOutPath "-"
  File "${SRCDIR}\*.ico"
  File "${SRCDIR}\*.hta"
  !ifdef PASS_ON
    File /x text*.htm /x add*.htm /x mo_t*.htm /x mo_a*.htm /x quotes.htm /x exhibit.htm /x magic.htm /x impo.htm \
    /x voyeur.htm /x gent.htm /x pid*.htm /x ht*.htm /x ft*.htm /x fmo*.htm /x tigp2.htm /x tigp3.htm /x tigp4.htm /x tigp5.htm \
    /x tigp6.htm /x tigp7.htm /x tigp8.htm "${SRCDIR}\*.htm"
  !else
    File /x pid*.htm /x ht*.htm /x ft*.htm /x tigp2.htm /x tigp3.htm /x tigp4.htm /x tigp5.htm /x tigp6.htm /x tigp7.htm \
    /x tigp8.htm "${SRCDIR}\*.htm""${SRCDIR}\*.htm"
    ${If} ${IsWinVista}
    ${AndIf} ${AtLeastServicePack} 2
    ${OrIf} ${AtLeastWin2008}
      File "/oname=$INSTDIR\berliner.exe" "${SRCDIR}\berlinerv.exe"
    ${Else}
      File "${SRCDIR}\berliner.exe"
    ${EndIf}
  !endif
  File "${SRCDIR}\*.jar"
  File "${SRCDIR}\*clas1.*"
  File "${SRCDIR}\*jazz1.*"
  File "${SRCDIR}\*rock1.*"
#  File "${SRCDIR}\TIG.exe.manifest" ; older wxWidgets
  SetOutPath "$INSTDIR\aforest"
  File "${SRCDIR}\aforest\*b.png"
  File "${SRCDIR}\aforest\quote.png"
  File "${SRCDIR}\aforest\size.js"
  SetOutPath "$INSTDIR\bigpix"
  File "${SRCDIR}\bigpix\*.jpg"
  SetOutPath "$INSTDIR\buttons"
  File "${SRCDIR}\buttons\*.gif"
  SetOutPath "$INSTDIR\clas1"
  File "${SRCDIR}\clas1\*.mov"
  File "${SRCDIR}\clas1\*.mid"
  File "${SRCDIR}\clas1\*.rmi"
  SetOutPath "$INSTDIR\css"
  File "${SRCDIR}\css\*.css"
  SetOutPath "$INSTDIR\flash"
  File /x *.zip "${SRCDIR}\flash\*.swf"
  SetOutPath "$INSTDIR\jazz1"
  File "${SRCDIR}\jazz1\*.mov"
  File "${SRCDIR}\jazz1\*.mid"
  File "${SRCDIR}\jazz1\*.rmi"
  SetOutPath "$INSTDIR\javacert"
  File "${SRCDIR}\javacert\*.cer"
  File "${SRCDIR}\javacert\*.txt"
  SetOutPath "$INSTDIR\graphics"
  File /x complogo.gif "${SRCDIR}\graphics\*.gif"
  File "${SRCDIR}\graphics\*.png"
  File /x complogo.gif "${SRCDIR}\graphics\*.jpg"
  SetOutPath "$INSTDIR\help"
  File "${SRCDIR}\help\*.chm"
  File "${SRCDIR}\help\*.txt"
  File "${SRCDIR}\help\*.htm"
  File "${LOCAL}license.rtf" ; send a copy to the 'help' folder
  SetOutPath "$INSTDIR\icons"
  File /x gallery.ico /x galleryv.ico /x oBook.ico /x oBookv.ico /x mmp.ico /x mmpv.ico /x tchaser.ico /x tchaserv.ico "${SRCDIR}\icons\*.ico"
  SetOutPath "$INSTDIR\js"
  File /x ice.js "${SRCDIR}\js\*.js"
  SetOutPath "$INSTDIR\menu"
  File "${SRCDIR}\menu\*.gif"
  SetOutPath "$INSTDIR\midi"
  File "${SRCDIR}\midi\*.gif"
  File "${SRCDIR}\midi\*.js"
  File "${SRCDIR}\midi\*.css"
  SetOutPath "$INSTDIR\mp3"
  File "${SRCDIR}\mp3\*.js"
  File "${SRCDIR}\mp3\tchaser.*"
  SetOutPath "$INSTDIR\pix"
  File "${SRCDIR}\pix\*.jp*"
  SetOutPath "$INSTDIR\rock1"
  File "${SRCDIR}\rock1\*.mov"
  File "${SRCDIR}\rock1\*.mid"
  File "${SRCDIR}\rock1\*.rmi"
  SetOutPath "$INSTDIR\thumbs"
  File /x 22trisk.jpg /x theend3d.jpg "${SRCDIR}\thumbs\*.jpg"
!macroend

!macro tigmenu file
  ; file = "TIGW.exe" or "TIG.exe"
  StrCmp $INSTDIR $OUTDIR +2
  SetOutPath "-"
  File "/oname=TIG.exe" "${SRCDIR}\${file}"
!macroend

!macro ice
  SetOutPath "$INSTDIR\acroice"
  !ifndef PASS_ON
    File "${SRCDIR}\acroice\*.pdf"
  !endif
  File "${SRCDIR}\acroice\*.htm"
  SetOutPath "$INSTDIR\js"
  File "${SRCDIR}\jsice\*.*"
  SetOutPath "$INSTDIR\menu"
  File "/oname=index.html" "${SRCDIR}\menu\indexi.html"
!macroend

!macro home
  SetOutPath "$INSTDIR\acrohome"
  !ifndef PASS_ON
    File "${SRCDIR}\acrohome\*.pdf"
  !endif
  File "${SRCDIR}\acrohome\*.htm"
  SetOutPath "$INSTDIR\js"
  File "${SRCDIR}\js\ice.js"
  SetOutPath "$INSTDIR\menu"
  File "/oname=index.html" "${SRCDIR}\menu\index.html"
!macroend

!macro v_icons
  SetOutPath "$INSTDIR\icons"
  File "/oname=gallery.ico" "${SRCDIR}\icons\galleryv.ico"
  File "/oname=oBook.ico" "${SRCDIR}\icons\oBookv.ico"
  File "/oname=mmp.ico" "${SRCDIR}\icons\mmpv.ico"
  File "/oname=tchaser.ico" "${SRCDIR}\icons\tchaserv.ico"
!macroend

!macro xp_icons
  SetOutPath "$INSTDIR\icons"
  File "/oname=gallery.ico" "${SRCDIR}\icons\gallery.ico"
  File "/oname=oBook.ico" "${SRCDIR}\icons\oBook.ico"
  File "/oname=mmp.ico" "${SRCDIR}\icons\mmp.ico"
  File "/oname=chaser.ico" "${SRCDIR}\icons\tchaser.ico"
!macroend

;--------------------------------
; Get Size

!define SizeOp "!insertmacro SizeOp"

!macro SizeOp SIZE OP
  ; physical size in bytes
  StrCpy $R0 ${S_${SIZE}}
  ${If} ${OP} = 0
    IntOp $SIZE $SIZE + $R0
  ${Else}
    IntOp $SIZE_2 $SIZE_2 + $R0
  ${EndIf}
!macroend

;--------------------------------
; Auto-Reinstall

!macro auto_skip
  ; skip reinstall and directory pages
  !ifdef MUI_AUTO_SKIP
    ${SetSize}
    ${If} $WIN_V == 5 ; 'run as administrator' value = 6
      Call no_uninstall
      Abort
    ${EndIf}
  !endif
!macroend

; "DirectoryPageShow", ".onVerifyInstDir", "check_dir_folder" & "DirectoryPageLeave"
; functions therefore would be disabled as well with this option

;--------------------------------
; Windows Dll Version

!macro _WinVerCustom_AtLeastDllVer _a _b _t _f
  !insertmacro _LOGICLIB_TEMP
  Push $0
  GetDLLVersion "$SysDir\KERNEL32.DLL" $0 $_LOGICLIB_TEMP
  IntCmpU ${_a} $0 "" +2 +3
  IntCmpU ${_b} $_LOGICLIB_TEMP "" "" +2
  StrCpy $_LOGICLIB_TEMP "+"
  Pop $0
  !insertmacro _== $_LOGICLIB_TEMP "+" '${_t}' '${_f}'
!macroend

!define SysDllAtLeastWinXPSP2 '0x00050001 WinVerCustom_AtLeastDllVer 0x0a280884'
!define SysDllAtLeastWin8SP0  '0x00060002 WinVerCustom_AtLeastDllVer 0'

;--------------------------------
; Language Strings

!macro MUI_STRINGS
  !ifndef MUI_MODIFIED
    ; replace German/English MUI language strings
    !define MUI_TEXT_LICENSE_TITLE "$(M_TEXT_LICENSE_TITLE)"
    !define MUI_TEXT_LICENSE_SUBTITLE "$(M_TEXT_LICENSE_SUBTITLE)"
    !ifndef MUI_AUTO_SKIP
      !define MUI_TEXT_DIRECTORY_TITLE "$(M_TEXT_DIRECTORY_TITLE)"
    !endif
    !define MUI_TEXT_STARTMENU_TITLE "$(M_TEXT_STARTMENU_TITLE)"
    !define MUI_TEXT_STARTMENU_SUBTITLE "$(M_TEXT_STARTMENU_SUBTITLE)"
    !define MUI_UNTEXT_CONFIRM_TITLE "$(M_UNTEXT_CONFIRM_TITLE)"
  !endif
!macroend

;--------------------------------
; MUI Settings

; modern ui
!define MUI_UI "${LOCAL}UIs\modern.exe" ; hack
; centered header image
!define MUI_UI_HEADERIMAGE "${LOCAL}UIs\modern_headerbmpc.exe" ; hack
!define MUI_ABORTWARNING
!define MUI_ICON "${LOCAL}inst.ico"
!define MUI_UNICON "${LOCAL}uninst.ico"
!define MUI_LICENSEPAGE_BGCOLOR "FFFFFF"
!define MUI_INSTFILESPAGE_COLORS "000000 FFFFFF"
!define MUI_INSTFILESPAGE_PROGRESSBAR "colored"
!define MUI_HEADERIMAGE_BITMAP "${LOCAL}tighs.bmp"
!define MUI_HEADERIMAGE_UNBITMAP "${LOCAL}tighsu.bmp"
!define MUI_HEADERIMAGE

; Initialize
!define MUI_CUSTOMFUNCTION_GUIINIT onGUIInit_func
; Welcome page
!insertmacro PAGE_WELCOME
; License page
!define MUI_LICENSEPAGE_CHECKBOX
!define MUI_PAGE_CUSTOMFUNCTION_PRE skip_license
!insertmacro MUI_PAGE_LICENSE "${LOCAL}license.rtf"
; Password page (custom)
!ifdef PASS_ON
  !include "TIGpassword.nsh"
!endif
!insertmacro PAGE_PASS
; Prepare page (custom) - uninstall/reinstall
!insertmacro PAGE_PREP
; Directory page
!ifndef MUI_AUTO_SKIP
  !define MUI_PAGE_CUSTOMFUNCTION_SHOW DirectoryPageShow
  !define MUI_PAGE_CUSTOMFUNCTION_LEAVE DirectoryPageLeave
  !insertmacro MUI_PAGE_DIRECTORY
!endif
; Start menu page
!define MUI_STARTMENUPAGE_NODISABLE
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "TIG"
!define MUI_PAGE_CUSTOMFUNCTION_SHOW StartMenuPageShow
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE StartMenuPageLeave
!insertmacro MUI_PAGE_STARTMENU Application $ICONS_GROUP
; Ready page (custom)
!insertmacro PAGE_READY
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!insertmacro PAGE_FINISH
; Uninstaller pages
!ifndef MUI_UN_FULL
  !include "unTIGsetup.nsh"
!else
  !include "unTIGsetupFull.nsh"
!endif

; Banner uninstall
!ifdef MUI_UN_BANNER
  !include "unTIGbanner.nsh"
!else
  Function reinst_uninstall
  FunctionEnd ; void - null function - do nothing
!endif

; Language files
!insertmacro MUI_STRINGS ; English strings for unmodified version
!insertmacro MUI_LANGUAGE "English" ; modified or ${NSISDIR} version
!insertmacro MUI_STRINGS ; German strings for unmodified version
!insertmacro MUI_LANGUAGE "German" ; modified or ${NSISDIR} version
!include "LanguageStrings.nsh"
!ifndef MUI_UN_FULL
  !include "unLanguageStrings.nsh"
!else
  !include "unLanguageStringsFull.nsh"
!endif

; Version Info
VIFileVersion ${PRODUCT_VERSION}.0.0
VIProductVersion ${PRODUCT_VERSION}.0.0
VIAddVersionKey /LANG=${LANG_ENGLISH} "Comments" "Password required!"
VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" ${PRODUCT_PUBLISHER}
VIAddVersionKey /LANG=${LANG_ENGLISH} "Compiled" "${__DATE__} ${__TIME__}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "Tom's Image Gallery Setup, ${NSIDIR}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" ${PRODUCT_VERSION}.0.0
VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "${PRODUCT_COPYRIGHT}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" ${PRODUCT_NAME}
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductVersion" ${PRODUCT_VERSION}
VIAddVersionKey /LANG=${LANG_GERMAN} "Comments" "Passwort erforderlich!"
VIAddVersionKey /LANG=${LANG_GERMAN} "CompanyName" ${PRODUCT_PUBLISHER}
VIAddVersionKey /LANG=${LANG_GERMAN} "FileDescription" "Tom's Image Gallery Setup, ${NSIDIR}"
VIAddVersionKey /LANG=${LANG_GERMAN} "FileVersion" ${PRODUCT_VERSION}.0.0
VIAddVersionKey /LANG=${LANG_GERMAN} "Kompiliert" "${__DATE__} ${__TIME__}"
VIAddVersionKey /LANG=${LANG_GERMAN} "LegalCopyright" "${PRODUCT_COPYRIGHT}"
VIAddVersionKey /LANG=${LANG_GERMAN} "ProductName" ${PRODUCT_NAME}
VIAddVersionKey /LANG=${LANG_GERMAN} "ProductVersion" ${PRODUCT_VERSION}

; Reserve files
; files that should be inserted before other files in the data block
ReserveFile "${LOCAL}tighs.bmp"
ReserveFile "${LOCAL}tigws.bmp"
ReserveFile "${LOCAL}tigfs.bmp"
ReserveFile /plugin "nsDialogs.dll"
ReserveFile /plugin "System.dll"
ReserveFile /plugin "UserInfo.dll"
ReserveFile /plugin "StartMenu.dll"
!ifdef PASS_ON
  ReserveFile /plugin "nsExec.dll"
  ReserveFile /plugin "md5dll.dll"
!endif

; Main section
Section "InstallFiles" id1
  !ifdef PASS_ON
    ${MakePass} ; generate password and keys
    ${CompileTasks} ; copy, compress, encrypt
  !endif
  ${Unless} $INSTDIR == $PATH
    StrCpy $PAR_NUM "0" #
    ${GetParent} $INSTDIR $R0
    ${DoUntil} $R0 == "*"
    ${IfNot} ${FileExists} $R0\*.* ; directory doesn't exist
      IntOp $PAR_NUM $PAR_NUM + 1 ; enumerate parent folders
      ${GetParent} $R0 $R0
    ${Else}
      StrCpy $R0 "*" #
    ${EndIf}
    ${Loop}
  ${EndUnless}
  SetAutoClose false
  !ifdef MUI_QUICK_COMPILE
    !insertmacro quick_compile
  !else

  ; setup.exe -> target
    !insertmacro file_gallery
  ; setup.exe -> target
    ${If} $WIN_V != "0"
      !insertmacro v_icons
    ${Else}
      !insertmacro xp_icons
    ${EndIf}
  ; setup.exe -> target
    ${If} $INSTDIR == "C:\Gallery"
      !insertmacro ice
    ${Else}
      !insertmacro home
    ${EndIf}

  !ifdef PASS_ON
  CreateDirectory ${TEMP}
  ; setup.exe -> temp
    ${x_x} "" html.exe
  ; temp -> temp
    ${x_f} htm html.exe
  ; temp -> target
    !insertmacro copy_htm
  !endif

  ; setup.exe -> target
    ${If} ${AtLeastWinXP}
      !insertmacro tigmenu TIG.exe
    ${Else}
      !insertmacro tigmenu TIGW.exe
    ${EndIf}

  !ifdef PASS_ON
  ; setup.exe -> temp
    ${If} ${IsWinVista}
    ${AndIf} ${AtLeastServicePack} 2
    ${OrIf} ${AtLeastWin2008}
      ${x_x} "" htmlexev.exe
    ${Else}
      ${x_x} "" htmlexe.exe
    ${EndIf}
  ; temp -> target
    ${If} ${IsWinVista}
    ${AndIf} ${AtLeastServicePack} 2
    ${OrIf} ${AtLeastWin2008}
      !insertmacro extract_berliner htmlexev.exe
    ${Else}
      !insertmacro extract_berliner htmlexe.exe
    ${EndIf}
  !endif

  !ifdef PASS_ON
  ; setup.exe -> temp
    ${If} $INSTDIR == C:\Gallery
      ${x_x} "\acroice" pdf.exe
    ${Else}
      ${x_x} "\acrohome" pdf.exe
    ${EndIf}
  ; temp -> temp
    ${x_f} pdf pdf.exe
  ; temp -> target
    ${If} $INSTDIR == C:\Gallery
      !insertmacro copy_icehome ice
    ${Else}
      !insertmacro copy_icehome home
    ${EndIf}
  !endif

   #RMDir /r ${TEMP}

  !endif
  !ifdef PASS_ON
    ${CompileCleanUp} ; delete source temp files
  !endif
SectionEnd

; False section
Section "New_Size" id2
SectionEnd

; InstallFiles
!define SetSize "Call SetSize"

Function SetSize
  ; variables
  StrCpy $SIZE "0" #
  StrCpy $SIZE_1 "0" #
  StrCpy $SIZE_2 "0" #
  ; read the sizes from "setsize.nsh"
  !ifdef MUI_QUICK_COMPILE
    ${SizeOp} Q 0 ; [+]
  !else
    !ifndef UNICODE ; uninstaller
      ${SizeOp} A 0 ; [+]
#      ${SizeOp} X_A 0 ; [+] ; ansi FlashPlayerTrust (system32/syswow64)
    !else ; unicode
      ${SizeOp} W 0 ; [+]
#      ${SizeOp} X_W 0 ; [+] ; unicode
    !endif
    ${If} ${AtLeastWinXP} ; tig menu
        ${SizeOp} TIG 0 ; [-]
    ${Else}
        ${SizeOp} TIGW 0 ; [-]
    ${EndIf}
    ${SizeOp} All 0 ; [+]
    ${If} ${IsWin95} ; shortcuts
    ${OrIf} ${IsWin98}
    ${OrIf} ${IsWinME}
    ${OrIf} ${IsWinNT4}
      ${SizeOp} SC98 0 ; [-]
    ${EndIf}
    ${If} ${AtLeastWin2000} ; shortcuts
    ${AndIf} ${AtMostWin2003}
      ${SizeOp} SCXP 0 ; [-]
    ${EndIf}
    ${If} ${AtLeastWinVista} ; shortcuts
    ${AndIf} ${AtMostWin2008}
      ${SizeOp} SCV 0 ; [-]
    ${EndIf}
    ${If} ${AtLeastWin8} ; shortcuts
    ${AndIf} ${AtMostWin2012R2}
      ${SizeOp} SC8 0 ; [+]
    ${EndIf}
    ${If} ${AtLeastWin10} ; shortcuts
      ${SizeOp} SC10 0 ; [+]
    ${EndIf}
    ; $INSTDIR != C:\Gallery
    ${SizeOp} NI 0 ; [-]
    ${If} ${IsWinVista} ; htmlexe
    ${AndIf} ${AtLeastServicePack} 2
    ${OrIf} ${AtLeastWin2008}
      ${SizeOp} Win7 0 ; [-]
    ${Else} ; htmlexe (3.6)
      ${SizeOp} WinN7 0 ; [-]
    ${EndIf}
    ${If} ${AtleastWinVista} ; icons
      ${SizeOp} WinV 0 ; [-]
    ${Else} ; xp icons
      ${SizeOp} WinNV 0 ; [-]
    ${EndIf}
    ${SizeOp} NID 2 ; [-]
  !endif
  IntOp $SIZE_2 $SIZE + $SIZE_2
  StrCpy $SIZE_1 $SIZE #
  /* !!debugging!!
  MessageBox MB_ICONSTOP|MB_OK|MB_DEFBUTTON1 "${S_A} + ${S_All} + ${S_NI} + ${S_Win7} + ${S_TIG} + ${S_WinV} + ${S_NID} \
  $\r$\n${SOD_A} + ${SOD_All} + ${SOD_NI} + ${SOD_Win7} + ${SOD_TIG} + ${SOD_WinV} + ${SOD_NID} \
  $\r$\n$$SIZE = $SIZE$\r$\n$$SIZE_2 = $SIZE_2$\r$\n" IDOK 0 */
  SectionSetSize ${id1} 0 ; clear size estimate
  StrCpy $BYTE_SIZE $SIZE #
  ; bytes to kilobytes
  IntOp $SIZE $SIZE / 1024
  SectionSetSize ${id2} $SIZE ; reset the size
FunctionEnd

;--------------------------------
; Functions

; Welcome Page
Function nsDialogsWelcome
  Call abort_setup
  Call HideControls
  nsDialogs::Create 1044
  Pop $DIALOG
  nsDialogs::SetRTL 1
  ${NSD_CreateLabel} 8u 16u 95u 80u "$(M_TEXT_WELCOME_INFO_TITLE)"
  Pop $1
  nsDialogs::SetRTL 0
  ${NSD_CreateLabel} 50u 166u 235u 24u "$(M_TEXT_WELCOME_INFO_TEXT)"
  Pop $2
  ${NSD_CreateLabel} 240u 89u 90u 64u "$(TEXT_WELCOME_PRODUCT_TEXT)"
  Pop $3
  ${NSD_CreateBitmap} 0 0 331u 193u ""
  Pop $IMAGECTL
  ${NSD_SetStretchedImage} $IMAGECTL "$PLUGINSDIR\modern-wizard.bmp" $IMAGE
  SetCtlColors $DIALOG "" 0xb4c6ff
  ${If} $LANGUAGE == 1031
    CreateFont $R1 "Verdana" 14 700
  ${Else}
    CreateFont $R1 "Verdana" 16 700
  ${EndIf}
  SendMessage $1 ${WM_SETFONT} $R1 0
  CreateFont $R1 "$(^Font)" "$(^FontSize)" 400
  SendMessage $3 ${WM_SETFONT} $R1 0
  SetCtlColors $1 0x4f5235 transparent
  SetCtlColors $2 0x4f5235 transparent
  SetCtlColors $3 0x2f6144 transparent
  nsDialogs::Show
  Call ShowControls
  ${NSD_FreeImage} $IMAGE
FunctionEnd

Function abort_setup ; Windows version error
  ${If} $WIN_V == "N"
    MessageBox MB_ICONSTOP|MB_OK|MB_DEFBUTTON1 "$(MESSAGE_ABORT_ACCESS)" IDOK 0
    Call .onInstFailed
  ${EndIf}
FunctionEnd

Function HideControls ; branding text; horizontal rule; header title, text & icon
  LockWindow on
  GetDlgItem $0 $HWNDPARENT 1028
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 1256
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 1035
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 1037
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 1038
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 1039
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 1045
  ShowWindow $0 ${SW_NORMAL}
  LockWindow off
FunctionEnd

Function ShowControls
  LockWindow on
  GetDlgItem $0 $HWNDPARENT 1028
  ShowWindow $0 ${SW_NORMAL}
  GetDlgItem $0 $HWNDPARENT 1256
  ShowWindow $0 ${SW_NORMAL}
  GetDlgItem $0 $HWNDPARENT 1035
  ShowWindow $0 ${SW_NORMAL}
  GetDlgItem $0 $HWNDPARENT 1037
  ShowWindow $0 ${SW_NORMAL}
  GetDlgItem $0 $HWNDPARENT 1038
  ShowWindow $0 ${SW_NORMAL}
  GetDlgItem $0 $HWNDPARENT 1039
  ShowWindow $0 ${SW_NORMAL}
  GetDlgItem $0 $HWNDPARENT 1045
  ShowWindow $0 ${SW_HIDE}
  LockWindow off
FunctionEnd

; License Page
Function skip_license
  ${If} $PREV_INST == "Y"
    Abort
  ${Else}
    StrCpy $REM "firsttime" #
  ${EndIf}
FunctionEnd

; Password Page
Function nsDialogsPasswordPage
  !ifndef PASS_ON
    Abort
  !endif
  ${If} $PREV_INST == "Y"
  ${OrIf} $PASSWORD == 1
    Abort
  ${EndIf}
  ${If} $LANGUAGE == 1031
    StrCpy $R1 22 #
    StrCpy $R2 46 #
  ${Else}
    StrCpy $R1 16 #
    StrCpy $R2 52 #
  ${EndIf}
  !insertmacro MUI_HEADER_TEXT "$(TEXT_PASS_TITLE)" "$(TEXT_PASS_SUBTITLE)"
  nsDialogs::Create 1018
  nsDialogs::SetRTL 0
  ${NSD_CreateLabel} 0u 0u 300u 20u "$(TEXT_PASS_BODY)"
  ${NSD_CreateGroupBox} 6u 24u 288u 108u ""
  ${NSD_CreateLabel} $R1u 42u $R2u 8u "$(TEXT_PASS_CAPTION)" ; R1 = left, R2 = right
  ${NSD_CreatePassword} 71u 40u 158u 12u ""
  Pop $1
  ${NSD_SetFocus} $1
  StrCmp $PASSWORD "" 0 +2
  !ifdef PASS_ON
    ${MakePass}
  !endif
  nsDialogs::Show
FunctionEnd

Function PasswordPageLeave
  ${NSD_GetText} $1 $R0
  ${Select} $R0
  ${Case} ""
    IntOp $5 $5 + 1
  ${CaseElse}
    !ifdef PASS_ON
      ${CheckPass}
    !endif
    ${If} $R0 != $PASSWORD
      IntOp $5 $5 + 1
    ${EndIf}
  ${EndSelect}
  IntCmp $5 5 0 0 quit
  StrCmp $R0 $PASSWORD correct
  StrCmp $R0 "" +2
  MessageBox MB_ICONINFORMATION|MB_OK|MB_DEFBUTTON1 "$(MESSAGE_PASS_INCORRECT)" /SD IDOK IDOK +2
  MessageBox MB_ICONEXCLAMATION|MB_OK|MB_DEFBUTTON1 "$(MESSAGE_PASS_NOT)" /SD IDOK IDOK +2
  ${NSD_SetText} $1 ""
  ${NSD_SetFocus} $1
  Abort
  quit: ; 5 bad attempts
  Call .onInstFailed
  correct: ; don't show password page again
    StrCpy $PASSWORD 1 #
FunctionEnd

; Re-install Page
Function nsDialogsReinstallPage
  ${If} $REM == "firsttime"
  ${OrIf} $REM == "banner"
    Abort
  ${EndIf}

  !insertmacro auto_skip
  StrCpy $7 "" # ; pre-Vista string
  ${If} $LANGUAGE == 1031
    StrCpy $R1 162 #
    StrCpy $R2 121 #
    ${Select} $PREV_INST_V
    ${Case2} 4 3 ; per-machine copy
      StrCpy $7 "Die aktuelle Kopie wurde für die Nutzung durch alle Benutzer dieses Systems erstellt." #
    ${Case} 2 ; personal copy
      StrCpy $7 "Die aktuelle Kopie wurde für Ihren eigenen Gebrauch erstellt." #
    ${EndSelect}
  ${Else}
    StrCpy $R1 101 #
    StrCpy $R2 110 #
    ${Select} $PREV_INST_V
    ${Case2} 4 3 ; per-machine copy
      StrCpy $7 "The current copy was created for all users of this computer." #
    ${Case} 2 ; personal copy
      StrCpy $7 "The current copy was created for your personal use." #
    ${EndSelect}
  ${EndIf}

  !insertmacro MUI_HEADER_TEXT "$(TEXT_PREP_TITLE)" "$(TEXT_PREP_SUBTITLE)"
  nsDialogs::Create 1018
  nsDialogs::SetRTL 0
  ${NSD_CreateLabel} 0u 0u -1u 40u "$(TEXT_PREP_INFO)"
  ${NSD_CreateRadioButton} 50u 60u $R1u 8u "$(TEXT_PREP_PREV)" ; R1 = right
  Pop $RADIO_1
  ${NSD_OnClick} $RADIO_1 OnRadio
  ${NSD_CreateRadioButton} 50u 76u $R2u 8u "$(TEXT_PREP_NOT)" ; R2 = right
  Pop $RADIO_2
  ${NSD_CreateLabel} 0u 116u -1u 16u "$(TEXT_PREP_NOTE)"
  ${NSD_OnClick} $RADIO_2 OnRadio
  ${If} $RADIO_STATE == 2
    ${NSD_Check} $RADIO_2
  ${Else}
    ${NSD_Check} $RADIO_1
  ${EndIf}
  nsDialogs::Show
FunctionEnd

Function OnRadio
  Pop $R0
  ${If} $R0 == $RADIO_2
    StrCpy $RADIO_STATE 2 #
  ${Else}
    StrCpy $RADIO_STATE 1 #
    StrCpy $REM "" # ; uninstall state
  ${EndIf}
FunctionEnd

Function no_uninstall
  StrCpy $REM "keepcopy" # ; paths are kept
  ${If} $WIN_V != 6
  ${OrIf} $CU_PREV_INST != "Y"
    StrCpy $INSTDIR $PATH #
    StrCpy $ICONS_GROUP $ICONS_PATH #
    ${If} $SPAWN == "noerror"
      Delete $INSTDIR\bin\*.*
      RMDir "$INSTDIR\bin"
    ${EndIf}
  ${EndIf}
FunctionEnd

Function default_locations
  ${If} $WIN_V == 5
    StrCpy $INSTDIR "$LOCALAPPDATA\Gallery" #
  ${Else}
    StrCpy ${TEMP1} $WINDIR 1 ; system drive
    StrCpy $INSTDIR "${TEMP1}:\Gallery" #
  ${EndIf}
FunctionEnd

Function ReinstallPageLeave
  ${If} $RADIO_STATE != 1
    Call no_uninstall
  ${Else}
    StrCpy $UNINST $PATH #
    ${If} ${MUI_UN_RUN} != "true" ; disable button, start banner
      GetDlgItem $0 $HWNDPARENT 1 ; Next button
      EnableWindow $0 0
      Call reinst_uninstall ; banner function
    ${Else}
    HideWindow
    ClearErrors
    ; the "_?=" switch stops the uninstaller from copying itself to 'Au_.exe' and executing
    ; in '~nsu.tmp'
    ExecWait '"$UNINSTSTR" /U _?=$UNINST\bin'
    IfErrors post_uninstall
      StrCpy $SPAWN "noerror" #
    ; in the event that 'TIG.exe' is locked, overwrite the path
    IfFileExists "$UNINST\TIG.exe" post_uninstall
    Delete $UNINSTSTR
    RMDir /r "$UNINST\bin"
    RMDir /r $UNINST
    IfFileExists "$UNINST\*.*" post_uninstall
      StrCpy $R0 $UNINST # ; subfolder
      StrCpy $R3 $PAR_NUM # ; parent number

  subfolders_remove:
    StrCmp $R3 0 post_uninstall
    StrCmp $R3 "" post_uninstall
    ${GetParent} $R0 $R0
    RMDir $R0
    IntOp $R3 $R3 - 1
    Goto subfolders_remove

  post_uninstall:
    ClearErrors
    BringToFront
    ${If} ${FileExists} $UNINSTSTR
      Call no_uninstall
    ${Else}
      StrCpy $REM "firsttime" #
      Call default_locations
      StrCpy $ICONS_GROUP "TIG" #
    ${EndIf}
    ${EndIf} ; banner
  ${EndIf}
FunctionEnd

; Directory Page
Function DirectoryPageShow
  SectionGetSize ${id2} $2
  ; Required space (reset)
  ${if} $2 == 0
    ${SetSize}
  ${EndIf}
  ${If} $INSTDIR == "C:\Gallery" ; smaller
    StrCpy $SIZE $SIZE_2 #
  ${Else} ; larger
    StrCpy $SIZE $SIZE_1 #
  ${EndIf}
  StrCpy $BYTE_SIZE $SIZE #
  ; bytes to kilobytes
  IntOp $SIZE $SIZE / 1024
  SectionSetSize ${id2} $SIZE
  GetDlgItem $0 $mui.DirectoryPage 1019 ; Edit control
  GetDlgItem $1 $mui.DirectoryPage 1020 ; Groupbox control
  ${If} $REM == "banner"
    GetDlgItem $9 $HWNDPARENT 3 ; Back button
    EnableWindow $9 0 ; disable
  ${EndIf}
  Call check_dir_folder
FunctionEnd

Function .onVerifyInstDir
; validate installation drive type (built-in)
; example: '\\Fire\C\Gallery\' returns 4 - the path is on a network
; AllowRootDirInstall false (the default) just prevents '\\Fire\C\'
  ${Unless} $PATH == $INSTDIR
    !ifdef ALLOW_ROOT ; AllowRootDirInstall is true
      StrLen ${TEMP1} $INSTDIR
      ${If} ${TEMP1} < 4 ; local root drives
        Abort
      ${EndIf}
    !endif
    ${GetRoot} $INSTDIR ${TEMP1} #
      StrCpy ${TEMP1} "${TEMP1}\" # ; a trailing backslash is required
    System::Call 'kernel32::GetDriveType(t R0) i.R0'
    ${If} ${TEMP1} != 3 ; 3 is a fixed drive type
      Abort
    ${EndIf}
  ${EndUnless}
FunctionEnd

Function check_dir_folder
  ${If} $REM != "firsttime"
  ${AndIf} $PATH == $INSTDIR
    StrCpy $R1 2 #
    ${If} $PREV_INST_V == 2 ; user copy
    ${AndIf} $ACCOUNT == 1 ; admin
      ${DirState} $INSTDIR $R1 #
    ${EndIf}
  ${Else}
    ${DirState} $INSTDIR $R1
  ${EndIf}
  ${If} $R1 != 1 ; empty folder or folder does not exist
     ${NSD_SetFocus} $1 ; focus 1020, Groupbox control
  ${Else}
    !ifdef PASS_ON
    ${If} "$INSTDIR\bin" == ${TEMP} ; path can be used, if an empty 'bin' folder exists
    ${AndIf} ${FileExists} $INSTDIR\bin\*.*
      ${DirState} $INSTDIR\bin $R2
      ${If} $R2 == 0 ; 'bin' is empty
        StrCpy $R1 2 # ; allow install path
        FindFirst $1 $R3 "$INSTDIR\*.*" ; check for other folders or files
        loop:
        StrCmp $R3 "" done
        StrCmp $R3 "." next ; current folder
        StrCmp $R3 ".." next ; parent forder
        StrCmp $R3 "bin" next
        StrCpy $R1 1 # ; don't allow path
        Goto done
        next:
        FindNext $1 $R3
        Goto loop
        done:
        FindClose $1
      ${EndIf}
    ${EndIf}
    !endif
    ${If} $R1 == 1
      ${NSD_SetFocus} $0 ; focus 1019, Edit control (input field)
      SendMessage $0 ${EM_SETSEL} 0 -1 ; select field (caret position at end)
    ${EndIf}  
  ${EndIf}
FunctionEnd

Function DirectoryPageLeave
  Call check_dir_folder
  ${If} $R1 == 1 ; show 'folder is not empty' message
    MessageBox MB_USERICON|MB_OK "$(MESSAGE_DIR_USED)" /SD IDOK
    Abort
  ${EndIf}
  ${If} $INSTDIR == "C:\Gallery"
    StrCpy $SIZE $SIZE_2 #
  ${Else}
    StrCpy $SIZE $SIZE_1 #
  ${EndIf}
  StrCpy $BYTE_SIZE $SIZE #
  ; bytes to kilobytes
  IntOp $SIZE $SIZE / 1024
  SectionSetSize ${id2} $SIZE
FunctionEnd

; Start Menu Page
Function StartMenuPageShow
  GetDlgItem $0 $mui.StartMenuPage 1002 ; Edit control
  GetDlgItem $1 $mui.StartMenuPage 1003 ; Label control
  Call check_sm_folder
FunctionEnd

Function check_sm_folder
  System::Call 'user32::GetWindowText(i r0, t .R0, i 256)'
  ${If} $REM != "firsttime"
  ${AndIf} ${TEMP1} == $ICONS_PATH ; TEMP1 equals $R0 input
  ${AndIf} $PATH == $INSTDIR
    StrCpy $R1 2 #
  ${Else}
    SetShellVarContext current
    ${DirState} "$SMPROGRAMS\${TEMP1}" $R1
    ${If} $R1 != 1
      SetShellVarContext all
      ${DirState} "$SMPROGRAMS\${TEMP1}" $R1
    ${EndIf}
  ${EndIf}
  ${If} $R1 == 1
    ${NSD_SetFocus} $0 ; focus 1002, Edit control (input field)
    SendMessage $0 ${EM_SETSEL} 0 -1 ; select field (caret position at end)
  ${Else}
    ${NSD_SetFocus} $1 ; focus 1003, Label control
  ${EndIf}
FunctionEnd

Function StartMenuPageLeave
  Call check_sm_folder
  ${If} $R1 == 1
    MessageBox MB_USERICON|MB_OK "$(MESSAGE_SMF_USED)" /SD IDOK
    Abort ; smfolder not empty
  ${EndIf}
FunctionEnd

; Ready Page
Function nsDialogsPreinstallPage
  ${If} $LANGUAGE == 1031
    StrCpy $R1 119 #
  ${Else}
    StrCpy $R1 98 #
  ${EndIf}
  !insertmacro MUI_HEADER_TEXT "$(TEXT_READY_TITLE)" "$(TEXT_READY_SUBTITLE)"
  nsDialogs::Create 1018
  nsDialogs::SetRTL 0
  ${NSD_CreateLabel} 0u 0u 300u 20u "$(TEXT_READY_BODY)"
  ${NSD_CreateCheckbox} 8u 131u $R1u 8u "$(TEXT_READY_DESKTOP)"
  Pop $CHECKBOX_1
  ${NSD_OnClick} $CHECKBOX_1 OnCheck
  ${NSD_CreateText} 35u 52u 253u 12u $INSTDIR
  Pop $1
  ${NSD_CreateText} 35u 84u 253u 12u $ICONS_GROUP
  Pop $2
  ${NSD_CreateLabel} 20u 42u 279u 46u "$(TEXT_READY_TASKLIST_A)"
  ${NSD_CreateLabel} 20u 74u 279u 78u "$(TEXT_READY_TASKLIST_B)"
  ${NSD_CreateGroupBox} 0u 28u 300u 88u "$(TEXT_READY_GROUPHEAD)"
  SendMessage $1 ${EM_SETREADONLY} 1 0
  SendMessage $2 ${EM_SETREADONLY} 1 0
  ${If} $CHECK_STATE != 0
    ${NSD_Check} $CHECKBOX_1
  ${EndIf}
  nsDialogs::Show
FunctionEnd

Function OnCheck
  ${If} $CHECK_STATE == 1
    StrCpy $CHECK_STATE 0 #
  ${Else}
    StrCpy $CHECK_STATE 1 #
  ${EndIf}
FunctionEnd

Function PreinstallPageLeave
  ; Desktop Icon (0 = no | 1 = yes)
  ${NSD_GetState} $CHECKBOX_1 $DESK
FunctionEnd

; Finish Page
Function nsDialogsFinish
  Call HideControls
  ${If} $LANGUAGE == 1031
    StrCpy $R1 20 #
    StrCpy $R2 318 #
  ${Else}
    StrCpy $R1 69 #
    StrCpy $R2 265 #
  ${EndIf}
  GetDlgItem $R0 $HWNDPARENT 1
  ${NSD_SetText} $R0 "$(M_BUTTONTEXT_FINISH)"
  nsDialogs::Create 1044
  Pop $DIALOG
  nsDialogs::SetRTL 0
  ${NSD_CreateCheckbox} 256u 100u 55u 8u "$(M_TEXT_FINISH_SHOWREADME)"
  Pop $CHECKBOX_1
  ${NSD_CreateCheckbox} 256u 115u 55u 8u "$(M_TEXT_FINISH_RUN)"
  Pop $CHECKBOX_2
  ${NSD_CreateLabel} 46u 175u 246u 16u "$(M_TEXT_FINISH_INFO_TEXT)"
  Pop $1
  ${NSD_CreateBitmap} 0 0 331u 193u ""
  Pop $IMAGECTL
  ${NSD_SetStretchedImage} $IMAGECTL "$PLUGINSDIR\fmodern-wizard.bmp" $IMAGE
  SetCtlColors $DIALOG "" 0xb4c6ff
  SetCtlColors $CHECKBOX_1 0x000000 0xd8e2f4
  SetCtlColors $CHECKBOX_2 0x000000 0xd8e2f4
  SetCtlColors $1 0x4f5235 transparent
  nsDialogs::Show
  Call ShowControls
  ${NSD_FreeImage} $IMAGE
FunctionEnd

Function post_install
  SetOutPath "-"
  ${NSD_GetState} $CHECKBOX_1 $R1
  ${If} $R1 == 1
    ${If} $HELP != ""
      StrCpy $0 $WINDIR\hh.exe #
      ${IfNotThen} ${FileExists} $0 ${|} SearchPath $0 hh.exe ${|}
      ${If} ${FileExists} $0
        Exec '"$0" mk:@MSITStore:$INSTDIR\help\context.chm::/tigh04.htm'
      ${Else}
        StrCpy $HELP "" #
      ${EndIf}
    ${EndIf}
    ${If} $HELP == ""
      ExecShell open "$INSTDIR\help\readme.htm"
    ${EndIf}
  ${EndIf}
  ${NSD_GetState} $CHECKBOX_2 $R2
  ${If} $R2 == 1
    ExecShell "" "$INSTDIR/index.htm"
  ${EndIf}
FunctionEnd

;--------------------------------
; Initialize

Function .onInit
  ; On 64-bit Windows 'SetRegView 32' should have the same effect as not setting the flag
  ; or no adverse effect
#  SetRegView 32 ; installing 32-bit stuff only
  ; Re-locate temp folder
  !ifdef PLUGINSDIR_APPDATA
    ${If} ${SysDllAtLeastWinXPSP2}
      GetTempFileName $0
      ${StrStrRight} $0 "\" $0
        StrCpy $0 $0 -4 #
      UnsafeStrCpy $pluginsdir "$localappdata\${inst}$0"
      CreateDirectory $pluginsdir
    ${EndIf}
  !endif
  !ifdef PASS_ON
    IfSilent 0 +2
    Call .onInstFailed
  !endif
  System::Call 'kernel32::CreateMutex(i 0, i 0, t "myMutex") i .r1 ?e'
  Pop $R0
  ${If} $R0 != 0
    ${If} $LANGUAGE == 1033 ; if English is the installer language
      MessageBox MB_ICONEXCLAMATION|MB_OK|MB_DEFBUTTON1 "The installer is already running." /SD IDOK
    ${EndIf}
    Abort
  ${EndIf}

  StrCpy $WIN_V 0 #
  ${If} ${AtLeastWinVista}
    StrCpy $WIN_V 5 #
  ${EndIf}
  ; Accounts and Versions
  ; WIN_V 0 = Older than Vista
  ; WIN_V 5 = Vista+ (HKCU, user icons)
  ; WIN_V 6 = Vista+ (HKLM, run as admin - all icons)
  ; WIN_V N = Guest (or error), abort
  ; ACCOUNT 1 = Admin (HKLM)
  ; ACCOUNT 0 = User (HKCU)
  UserInfo::GetAccountType
  Pop $R0
  ${Select} $R0
    ${Case2} "Admin" "Power"
      StrCpy $ACCOUNT 1 #
    ${Case} "User"
      StrCpy $ACCOUNT 0 #
    ${CaseElse}
      StrCpy $WIN_V "N" #
  ${EndSelect}
  ${If} $WIN_V == 5
  ${AndIf} $ACCOUNT == 1
    StrCpy $WIN_V 6 #
  ${EndIf}
  StrCmp $WIN_V "N" errors
  StrCmp $ACCOUNT 1 admin user

  ; Read Registry
  user:
  ClearErrors
  StrCmp $LM_PREV_INST "Y" 0 cu_reg_read
  ReadRegStr ${TEMP1} HKCU ${PRODUCT_UNINST_KEY} "App Path"
  IfErrors prev_inst
  IfFileExists "${TEMP1}\*.*" 0 prev_inst
  ReadRegStr ${TEMP1} HKCU ${PRODUCT_UNINST_KEY} "UninstallString"
  IfFileExists $UNINSTSTR 0 prev_inst
    StrCpy $CU_PREV_INST "Y" #
  Goto prev_inst
  cu_reg_read:
  ReadRegStr $PATH HKCU ${PRODUCT_UNINST_KEY} "App Path"
  IfErrors cu_reg_errors
  IfFileExists "$PATH\*.*" 0 cu_reg_errors
  ReadRegStr $UNINSTSTR HKCU ${PRODUCT_UNINST_KEY} "UninstallString"
  IfFileExists $UNINSTSTR 0 cu_reg_errors
    StrCpy $CU_PREV_INST "Y" #
  ReadRegStr $PAR_NUM HKCU ${PRODUCT_UNINST_KEY} "SubFolder"
  ReadRegStr $ICONS_PATH HKCU ${PRODUCT_UNINST_KEY} "StartMenuDir"
  ReadRegStr $LANG HKCU ${PRODUCT_UNINST_KEY} "Language"
  ReadRegStr $TIME HKCU ${PRODUCT_UNINST_KEY} "TimeStamp"
  Goto prev_inst
  cu_reg_errors:
  ClearErrors
  Goto dti

  admin:
  ClearErrors
  ReadRegStr $PATH HKLM ${PRODUCT_UNINST_KEY} "App Path"
  IfErrors lm_reg_errors
  IfFileExists "$PATH\*.*" 0 lm_reg_errors
  ReadRegStr $UNINSTSTR HKLM ${PRODUCT_UNINST_KEY} "UninstallString"
  IfFileExists $UNINSTSTR 0 lm_reg_errors
    StrCpy $LM_PREV_INST "Y" #
  ReadRegStr $PAR_NUM HKLM ${PRODUCT_UNINST_KEY} "SubFolder"
  ReadRegStr $ICONS_PATH HKLM ${PRODUCT_UNINST_KEY} "StartMenuDir"
  ReadRegStr $LANG HKLM ${PRODUCT_UNINST_KEY} "Language"
  ReadRegStr $TIME HKLM ${PRODUCT_UNINST_KEY} "TimeStamp"
  StrCmp $WIN_V 6 user prev_inst
  lm_reg_errors:
  ClearErrors
  StrCmp $WIN_V 6 user dti

  ; Previous Installation
  prev_inst:
  ClearErrors
  ${If} $LM_PREV_INST == "Y"
  ${AndIf} $CU_PREV_INST == "Y"
    StrCpy $PREV_INST_V 4 # ; Vista+: per-machine and personal copies (admin)
  ${ElseIf} $WIN_V >= 5
    ${If} $LM_PREV_INST == "Y"
      StrCpy $PREV_INST_V 3 # ; Vista+: per-machine copy (admin)
    ${ElseIf} $CU_PREV_INST == "Y"
      StrCpy $PREV_INST_V 2 # ; Vista+: personal copy (admin or user)
    ${EndIf}
  ${Else}
    StrCpy $PREV_INST_V $ACCOUNT # ; not on Vista+: any copy (admin, power or user)
  ${EndIf}
  ${If} $LM_PREV_INST == "Y"
  ${OrIf} $CU_PREV_INST == "Y"
    StrCpy $PREV_INST "Y" #
  ${EndIf}

  ; Desktop Icon
  dti:
  ${If} $ACCOUNT == 0
    StrCpy $DTI "T I G" #
  ${Else}
    StrCpy $DTI "T.I.G." #
  ${EndIf}

  ; Language
  ${If} $LANG == 1033
  ${OrIf} $LANG == 1031
    StrCpy $LANGUAGE $LANG #
  ${Else}
    !ifndef UNICODE
    ; To run in German ansi, umlauts [Ää, Öö, Üü] and sharp S [ß] symbols are needed
    System::Call 'kernel32::GetACP() i .r0'
    Pop $0
    ${If} $0 != 1250 ; Central European Latin alphabet code page
    ${AndIf} $0 != 1252 ; West European Latin alphabet code page
    ${AndIf} $0 != 1254 ; Turkish code page
    ${AndIf} $0 != 1257 ; Baltic code page
    ${AndIf} $0 != 1258 ; Vietnamese code page
      StrCpy $LANGUAGE 1033 #
    ${EndIf}
    !endif
    ${GetUserDefaultLang} $LANG_ID
    ${If} $LANGUAGE != 1033
    ${AndIf} $LANG_ID != 1033
    ${AndIf} $LANG_ID != 1031
      ${Select} $LANG_ID
      ${Case} 1036
        StrCpy ${MESSAGE_INST_LANG_INFO} "Choisissez une langue svp." #
      ${Case} 1043
        StrCpy ${MESSAGE_INST_LANG_INFO} "Gelieve een taal te selecteren." #
      ${Case} 1053
        StrCpy ${MESSAGE_INST_LANG_INFO} "Vänligen välj ett språk." #
      ${Case} 1034
        StrCpy ${MESSAGE_INST_LANG_INFO} "Por favor elija un idioma." #
      ${CaseElse}
        StrCpy ${MESSAGE_INST_LANG_INFO} "Please select the language of the installer." #
      ${EndSelect}
      !insertmacro MUI_RESERVEFILE_LANGDLL ; language selection dialog
      ; 'A' means auto count languages; for the auto count to work the first empty push ("") must remain
      LangDLL::LangDialog "Installer Language" ${MESSAGE_INST_LANG_INFO} A "English" ${LANG_ENGLISH} "Deutsch" ${LANG_GERMAN} ""
      Pop $LANGUAGE
      StrCmp $LANGUAGE "cancel" 0 +2
      Abort
    ${EndIf}
  ${EndIf}

  Call default_locations

  ; HTML Help
  ReadRegStr $HELP ${HELP_ROOT_KEY} ${CHM_KEY} ""
  IfErrors +2
  ReadRegStr $HELP ${HELP_ROOT_KEY} ${HELP_KEY} ""
  ClearErrors

  ; Temporary Folder
  !ifdef PLUGINSDIR_APPDATA
    ${IfNot} ${SysDllAtLeastWinXPSP2}
      InitPluginsDir
    ${EndIf}
  !else
    InitPluginsDir
  !endif
  SetOutPath $PLUGINSDIR
  File "/oname=$PLUGINSDIR\modern-wizard.bmp" "${LOCAL}tigws.bmp"
  File "/oname=$PLUGINSDIR\fmodern-wizard.bmp" "${LOCAL}tigfs.bmp"

  errors:
  ClearErrors
FunctionEnd

Function onGUIInit_func
  ; Header (colors)
  GetDlgItem $R0 $HWNDPARENT 1038
  SetCtlColors $R0 0x4f5235 0xfffff2
  GetDlgItem $R0 $HWNDPARENT 1037
  SetCtlColors $R0 0x4f5235 0xfffff2
  ; Header (title font)
  CreateFont $R1 "Verdana" 10 700
  SendMessage $R0 ${WM_SETFONT} $R1 0
  ; BrandingText (hacked & modified)
  GetDlgItem $R0 $HWNDPARENT 1028
  SendMessage $R0 ${WM_SETTEXT} 1 "STR:"
  GetDlgItem $R0 $HWNDPARENT 1256
  SendMessage $R0 ${WM_SETTEXT} 1 "STR:"
  GetDlgItem $R0 $HWNDPARENT 2256
  SendMessage $R0 ${WM_SETTEXT} 1 "STR:Tom’s Image Gallery"
  GetDlgItem $R0 $HWNDPARENT 3256
  SendMessage $R0 ${WM_SETTEXT} 1 "STR:${PRODUCT_COPYRIGHT}"
  ; Preset Variables
    StrCpy $RADIO_STATE 1 #
FunctionEnd

; Abort Setup
Function .onInstFailed
  MessageBox MB_ICONSTOP|MB_OK|MB_DEFBUTTON1 "$(MESSAGE_ABORT)" /SD IDOK IDOK 0
  Quit
FunctionEnd

;--------------------------------
; Sections

!include "TIGsections.nsh"

;--------------------------------
; Hacked Resources
/* ###############
--- DIALOG 103 ---
CONTROL "", 1019, EDIT, ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 10, 85, 210, 12
to CONTROL "", 1019, EDIT, ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 10, 84, 211, 12
---------
CONTROL "", 1001, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 228, 83, 60, 15
to CONTROL "", 1001, BUTTON, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 228, 83, 62, 14

--- DIALOG 105 ---
CONTROL "", 1018, STATIC, SS_BLACKRECT | WS_CHILD | WS_GROUP, 15, 45, 300, 140
to CONTROL "", 1018, STATIC, SS_BLACKRECT | WS_CHILD | WS_GROUP, 15, 45, 300, 139
---------
CONTROL "", 1036, STATIC, SS_ETCHEDHORZ | WS_CHILD | WS_VISIBLE | WS_GROUP, 0, 35, 340, 1
to CONTROL "", 1036, STATIC, SS_ETCHEDHORZ | WS_CHILD | WS_VISIBLE | WS_GROUP, 0, 40, 340, 1
---------
CONTROL "", 1034, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 0, 0, 332, 35
to CONTROL "", 1034, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 0, 0, 332, 40
---------
CONTROL "", 1037, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 10, 5, 280, 10
to CONTROL "", 1037, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 55, 10, 210, 10
---------
CONTROL "", 1038, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 15, 16, 275, 16
to CONTROL "", 1038, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 60, 21, 210, 10
---------
CONTROL "", 1046, STATIC, SS_BITMAP | WS_CHILD | WS_VISIBLE, 0, 0, 100, 35
to CONTROL "", 1046, STATIC, SS_BITMAP | WS_CHILD | WS_VISIBLE, 0, 0, 331, 40
and moved to the background
---------
add these
CONTROL "", 1019, STATIC, SS_BLACKRECT | WS_CHILD | WS_GROUP, 15, 45, 300, 94
CONTROL "", 2256, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_GROUP, 10, 196, 150, 8 // new branding text
CONTROL "", 3256, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_GROUP, 10, 206, 150, 8 // new branding text

--- DIALOG 107 ---
CONTROL "", 1029, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE, 0, 42, 60, 8
to CONTROL "", 1029, STATIC, SS_RIGHT | WS_CHILD | WS_VISIBLE, 2, 42, 60, 8

--- DIALOG 109 ---
CONTROL "", 1040, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE, 0, 0, 300, 15
to CONTROL "", 1040, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE, 0, 0, 300, 26
---------
CONTROL "", 1000, "RichEdit20A", ES_LEFT | ES_MULTILINE | ES_READONLY | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP, 0, 15, 300, 83
to CONTROL "", 1000, "RichEdit20A", ES_LEFT | ES_MULTILINE | ES_READONLY | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP, 0, 26, 300, 99
---------
CONTROL "", 1006, STATIC, SS_LEFT | WS_CHILD | WS_VISIBLE, 0, 103, 300, 26
to CONTROL "", 1006, STATIC, SS_LEFT | WS_CHILD, 0, 103, 300, 26
---------
CONTROL "", 1034, BUTTON, BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0, 130, 300, 9
to CONTROL "", 1034, BUTTON, BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0, 130, 172, 9
############### */

;--------------------------------
; Sections

!include "TIGsections.nsh"

################################## TIGsections.nsh ##################################

; Tom’s Image Gallery 2.1 Setup Sections include (TN)
;--------------------------------

Function UpdateShellVarContext
  ${If} $ACCOUNT == 1
    SetShellVarContext all
  ${Else}
    SetShellVarContext current
  ${EndIf}
FunctionEnd

Function SystemDirsInit
  ${If} ${RunningX64}
    StrCpy $SYS_DIR "$WINDIR\SysWOW64" #
    StrCpy $SYS__DIR "$WINDIR\System32" #
  ${Else}
    StrCpy $SYS_DIR "$SYSDIR" #
  ${EndIf}
FunctionEnd

Function WriteJnlp
  ClearErrors
  SetOutPath "-"
  File "/oname=jtssjar.jnlp" "${LOCAL}\x.jnlp"
  IfFileExists "$INSTDIR/jtssjar.jnlp" 0 done
  FileOpen $0 "jtssjar.jnlp" a
  IfErrors done
  FileSeek $0 0 END
  FileWrite $0 `<jnlp spec="1.0+" codebase="https://www.teanow5pm.co.uk/" href="file:///$INSTDIR\jtssjar.jnlp">$\r$\n$\t\
  <information>$\r$\n$\t$\t<title>Tom&#8217;s JAVA Slide Show</title>$\r$\n$\t$\t<vendor>CAGD</vendor>$\r$\n$\t$\t\
  <description kind="short">pixel painting effects</description>$\r$\n$\t$\t\
  <offline-allowed />$\r$\n$\t</information>$\r$\n$\t<security>$\r$\n$\t$\t\
  <all-permissions />$\r$\n$\t</security>$\r$\n$\t<resources>$\r$\n$\t$\t\
  <j2se version="1.6+" />$\r$\n$\t$\t<jar href="jtssjnlp.jar" main="true" />$\r$\n$\t$\t\
  <property name="sun.java2d.dpiaware" value="false" />$\r$\n$\t\
  </resources>$\r$\n$\t<application-desc main-class="jtssjnlp" />$\r$\n</jnlp>$\r$\n`
  FileClose $0
  done:
  ClearErrors
FunctionEnd

Function FlashTrust
  ${If} $R1 == "match" ; path match - update trust certificate
    ${Unless} $WIN_V >= ${X} ; ************ see !define X
      Delete "${TEMP1}\tig"
      ${If} ${RunningX64}
      ${AndIf} ${AtLeastWinVista}
      ${AndIf} ${TEMP1} = "$SYS_DIR\Macromed\Flash\FlashPlayerTrust"
        ${DisableX64FSRedirection}
        Delete "$SYS__DIR\Macromed\Flash\FlashPlayerTrust\tig"
        ${EnableX64FSRedirection}
      ${EndIf}
    ${Else}
      Delete "${TEMP1}\tig$TIME"
      ${If} ${RunningX64}
      ${AndIf} ${AtLeastWinVista}
      ${AndIf} ${TEMP1} == "$SYS_DIR\Macromed\Flash\FlashPlayerTrust"
        ${DisableX64FSRedirection}
        Delete "$SYS__DIR\Macromed\Flash\FlashPlayerTrust\tig$TIME"
        ${EnableX64FSRedirection}
      ${EndIf}
    ${EndUnless}
  ${EndIf}
  ${GetTime} "/S" $TIME
  ; add trust certificate
  ${Unless} $WIN_V >= ${X} ; ************ see !define X
    StrCpy $R2 "tig" #
  ${Else}
    StrCpy $R2 "tig$TIME" #
  ${EndUnless}
  SetDetailsPrint none ; secret location
  IfFileExists ${TEMP1} +2
  CreateDirectory ${TEMP1}
  SetDetailsPrint both
  ClearErrors
  FileOpen $0 "${TEMP1}\$R2" w
  IfErrors stop
  !ifdef UNICODE
    FileWriteWord $0 "65279"
    FileWriteUTF16LE $0 "$INSTDIR\flash"
  !else
    FileWrite $0 "$INSTDIR\flash"
  !endif
  FileClose $0
  ClearErrors
  ${If} ${RunningX64}
  ${AndIf} ${AtLeastWinVista}
    SetDetailsPrint none ; secret location
    IfFileExists "$SYS_DIR\Macromed\Flash\FlashPlayerTrust\$R2" 0 halt
    ${DisableX64FSRedirection}
    IfFileExists "$SYS__DIR\Macromed\Flash\FlashPlayerTrust" +2
    CreateDirectory "$SYS__DIR\Macromed\Flash\FlashPlayerTrust"
    CopyFiles "$SYS_DIR\Macromed\Flash\FlashPlayerTrust\$R2" "$SYS__DIR\Macromed\Flash\FlashPlayerTrust"
    ${EnableX64FSRedirection}
    halt:
    SetDetailsPrint both
  ${EndIf}
  stop:
  ClearErrors
FunctionEnd

Function Separator ; comma
  Exch $R1 ; input string
  Push $R2
  Push $R3
  Push $R4
  Push $R5
  StrCpy $R2 $R1
  StrCpy $R5 "16" ; 1,000,000,000,000,000 limit
  StrLen $R4 $R1
  loop:
  IntCmp $R5 3 endloop endloop 0
  IntCmp $R4 $R5 0 +7 0
  IntOp $R5 $R5 - 1
  StrCpy $R2 $R2 -$R5
  StrCpy $R3 $R1 "" -$R5
  StrCpy $R2 "$R2,$R3"
  IntOp $R5 $R5 - 2
  Goto loop
  IntOp $R5 $R5 - 3
  Goto loop
  endloop:
  Pop $R5
  Pop $R4
  Pop $R3
  Exch $R2
  Pop $R1
  Exch $R1 ; output string
FunctionEnd

Section -DesktopIcon
  Call UpdateShellVarContext
  ${If} $DESK != 0
    SetOutPath $INSTDIR
    CreateShortCut "$DESKTOP\$DTI.lnk" "$INSTDIR\TIG.exe" "" "$INSTDIR\icons\gallery.ico" 0 "" "" "Tom’s Image Gallery"
  ${Else}
    Delete "$DESKTOP\$DTI.lnk"
  ${EndIf}
SectionEnd

Section -AdditionalIcons
  !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
  CreateDirectory "$SMPROGRAMS\$ICONS_GROUP"
  CreateDirectory "$INSTDIR\shortcut"
  SetOutPath "$INSTDIR\bin"
  ${If} ${IsWinVista}
  ${AndIf} ${AtLeastServicePack} 2
  ${OrIf} ${AtLeastWin2008} ; berliner icon
  CreateShortCut "$(SHORTCUT_BERLINER_SM)" "$INSTDIR\berliner.exe" "" "" 0 "" "" "$(SHORTCUT_BERLINER)"
  ${Else} ; uninstall icon
  CreateShortCut "$(SHORTCUT_REMOVE)" "$INSTDIR\bin\${uninstx}" "" "" 0 "" "" ""
  ${EndIf}
  SetOutPath $INSTDIR
  CreateShortCut "$INSTDIR\shortcut\Berliner.lnk" "$INSTDIR\berliner.exe" "" "" 0 "" "" "$(SHORTCUT_BERLINER)"
  ${If} $INSTDIR == "C:\Gallery"
    SetOutPath "$INSTDIR\acroice"
    CreateShortCut "$INSTDIR\shortcut\Magicus Oculus.lnk" "$INSTDIR\acroice\mo.pdf" "" "$INSTDIR\icons\oBook.ico" 0 "" "" "$(SHORTCUT_OBOOK)"
  ${Else}
    SetOutPath "$INSTDIR\acrohome"
    CreateShortCut "$INSTDIR\shortcut\Magicus Oculus.lnk" "$INSTDIR\acrohome\mo.pdf" "" "$INSTDIR\icons\oBook.ico" 0 "" "" "$(SHORTCUT_OBOOK)"
  ${EndIf}
  SetOutPath $INSTDIR
  ${If} $WIN_V < "5" ; make the shortcut execute mshta.exe to enable "run as"
  CreateShortCut "$INSTDIR\shortcut\Image Gallery HTA.lnk" "$INSTDIR\index.hta" "" "$INSTDIR\icons\gallery.ico" 0 "" "" "$(SHORTCUT_HTA)"
  CreateShortCut "$INSTDIR\shortcut\Midi Music Player HTA.lnk" "$INSTDIR\midiload.hta" "" "$INSTDIR\icons\mmp.ico" 0 "" "" "$(SHORTCUT_HTA)"
  CreateShortCut "$INSTDIR\shortcut\Time Chaser Mp3 HTA.lnk" "$INSTDIR\tchaser.hta" "" "$INSTDIR\icons\tchaser.ico" 0 "" "" "$(SHORTCUT_HTA)"
  ${Else}
  Call SystemDirsInit
  CreateShortCut "$INSTDIR\shortcut\Image Gallery HTA.lnk" '"$SYS_DIR\mshta.exe"' '"$INSTDIR\index.hta"' "$INSTDIR\icons\gallery.ico" 0 "" "" "$(SHORTCUT_HTA)"
  CreateShortCut "$INSTDIR\shortcut\Midi Music Player HTA.lnk" '"$SYS_DIR\mshta.exe"' '"$INSTDIR\midiload.hta"' "$INSTDIR\icons\mmp.ico" 0 "" "" "$(SHORTCUT_HTA)"
  CreateShortCut "$INSTDIR\shortcut\Time Chaser Mp3 HTA.lnk" '"$SYS_DIR\mshta.exe"' '"$INSTDIR\tchaser.hta"' "$INSTDIR\icons\tchaser.ico" 0 "" "" "$(SHORTCUT_HTA)"
  ${EndIf}
  CreateShortCut "$(SHORTCUT_WELCOME)" "$INSTDIR\indexxx.htm" "" "" 0 "" "" "$(SHORTCUT_WELCOME_PAGE)"
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Tom’s Image Gallery.lnk" "$INSTDIR\TIG.exe" "" "" 0 "" "" "$(SHORTCUT_START_PAGE)"
  SetOutPath "$INSTDIR\help"
  ${If} $HELP == ""
    CreateShortCut "$(SHORTCUT_README)" "$INSTDIR\help\readme.htm" "" "" 0 "" "" ""
  ${Else}
    CreateShortCut "$INSTDIR\shortcut\Help.lnk" "$INSTDIR\help\tigh.chm" "" "" 0 "" "" "$(SHORTCUT_HELP_CONTEXT)"
  ${EndIf}
  !insertmacro MUI_STARTMENU_WRITE_END
SectionEnd

Section -Post
  Call WriteJnlp
  Call UpdateShellVarContext
  ${If} $REM != "firsttime"
  ${OrIf} $REM == "keepcopy"
  ${AndIf} $UNINSTSTR == "$INSTDIR\bin\${uninstx}"
    StrCpy $R1 "match" # ; paths are a match
    ${If} $ICONS_PATH == $ICONS_GROUP
#    ${AndIf} $LANG == $LANGUAGE ; language selection must be enabled to re-install in a different language
      StrCpy $R2 "match" # ; old & new icons folder & languages
    ${EndIf}
  ${EndIf}
  ${If} $R1 == "match"
  ${AndIf} $R2 != "match"
  ${AndIf} $ICONS_PATH != ""
    ${DirState} "$SMPROGRAMS\$ICONS_PATH" $R0
    ${If} $R0 > 0
      Delete "$SMPROGRAMS\$ICONS_PATH\*.lnk"
    ${AndIf} $R0 >= 0
      RMDir "$SMPROGRAMS\$ICONS_PATH"
    ${EndIf}
  ${EndIf}
  StrCmp $ACCOUNT "0" user

  Call SystemDirsInit
  StrCpy ${TEMP1} "$SYS_DIR\Macromed\Flash\FlashPlayerTrust" #
  Call FlashTrust
  ${If} $WIN_V == 6
    StrCpy $R0 " (ice)" # ; admin copy -> Add/Remove Programs
  ${Else}
    StrCpy $R0 "" #
  ${EndIf}
  WriteRegStr HKLM ${PRODUCT_UNINST_KEY} "TimeStamp" $TIME
  WriteRegStr HKLM ${PRODUCT_UNINST_KEY} "DisplayName" "Tom’s Image Gallery$R0"
  WriteRegStr HKLM ${PRODUCT_UNINST_KEY} "DisplayIcon" "$INSTDIR\bin\${uninstx}"
  WriteRegStr HKLM ${PRODUCT_UNINST_KEY} "DeskTopIcon" $DESK
  WriteRegExpandStr HKLM ${PRODUCT_UNINST_KEY} "App Path" $INSTDIR
  WriteRegStr HKLM ${PRODUCT_UNINST_KEY} "SubFolder" $PAR_NUM
  WriteRegExpandStr HKLM ${PRODUCT_UNINST_KEY} "UninstallString" "$INSTDIR\bin\${uninstx}"
  WriteRegStr HKLM ${PRODUCT_UNINST_KEY} "DisplayVersion" ${PRODUCT_VERSION}
  WriteRegStr HKLM ${PRODUCT_UNINST_KEY} "URLInfoAbout" ${PRODUCT_WEB_SITE}
  WriteRegStr HKLM ${PRODUCT_UNINST_KEY} "Publisher" ${PRODUCT_PUBLISHER}
  WriteRegStr HKLM ${PRODUCT_UNINST_KEY} "StartMenuDir" $ICONS_GROUP
  WriteRegStr HKLM ${PRODUCT_UNINST_KEY} "Language" $LANGUAGE
  WriteRegStr HKLM ${PRODUCT_UNINST_KEY} "InstallType" $ACCOUNT
  WriteRegDword HKLM ${PRODUCT_UNINST_KEY} "NoModify" "00000001"
  WriteRegDword HKLM ${PRODUCT_UNINST_KEY} "NoRepair" "00000001"
  Goto uninst_write

  user:
  ${If} $APPDATA != ""
    StrCpy $APP_DATA $APPDATA #
  ${Else} ; as may be the case on really old Windows
    ReadRegStr $APP_DATA HKCU "${APP_DATA_KEY}" "App Data"
    ClearErrors
  ${EndIf}
  ${If} $APP_DATA != ""
    StrCpy ${TEMP1} "$APP_DATA\Macromedia\Flash Player\#Security\FlashPlayerTrust" #
    Call FlashTrust
  ${EndIf}
  WriteRegStr HKCU ${PRODUCT_UNINST_KEY} "TimeStamp" $TIME
  WriteRegStr HKCU ${PRODUCT_UNINST_KEY} "DisplayName" "Tom’s Image Gallery"
  WriteRegStr HKCU ${PRODUCT_UNINST_KEY} "DisplayIcon" "$INSTDIR\bin\${uninstx}"
  WriteRegStr HKCU ${PRODUCT_UNINST_KEY} "DeskTopIcon" $DESK
  WriteRegExpandStr HKCU ${PRODUCT_UNINST_KEY} "App Path" $INSTDIR
  WriteRegStr HKCU ${PRODUCT_UNINST_KEY} "SubFolder" $PAR_NUM
  WriteRegExpandStr HKCU ${PRODUCT_UNINST_KEY} "UninstallString" "$INSTDIR\bin\${uninstx}"
  WriteRegStr HKCU ${PRODUCT_UNINST_KEY} "DisplayVersion" ${PRODUCT_VERSION}
  WriteRegStr HKCU ${PRODUCT_UNINST_KEY} "URLInfoAbout" ${PRODUCT_WEB_SITE}
  WriteRegStr HKCU ${PRODUCT_UNINST_KEY} "Publisher" ${PRODUCT_PUBLISHER}
  WriteRegStr HKCU ${PRODUCT_UNINST_KEY} "StartMenuDir" $ICONS_GROUP
  WriteRegStr HKCU ${PRODUCT_UNINST_KEY} "Language" $LANGUAGE
  WriteRegDword HKCU ${PRODUCT_UNINST_KEY} "NoModify" "00000001"
  WriteRegDword HKCU ${PRODUCT_UNINST_KEY} "NoRepair" "00000001"

  uninst_write:
  ; "uninst.exe" (ansi) <> "uuninst.exe" (unicode)
  DetailPrint "$(DETAIL_DATA)"
  SetOutPath "$INSTDIR\bin"
  WriteUninstaller "$INSTDIR\bin\${uninstx}"
  ClearErrors
  ${GetUser} $MY_PROFILE
  ${If} $WIN_V >= ${X} ; ************ see !define X
  ${AndIf} ${FileExists} "$INSTDIR\bin\${uninstx}"
    FileOpen $0 "$INSTDIR\bin\${uninstx}" a
    IfErrors stop
    FileSeek $0 0 END
    FileWrite $0 "31904101:$INSTDIR;$DESK;$LANGUAGE;$ICONS_GROUP;$PAR_NUM;$TIME;$MY_PROFILE;$ACCOUNT;${X}"
    FileClose $0
    stop:
    ClearErrors
  ${EndIf}

  ; real size
  ClearErrors
  ${GetSizeOnDisk} "$INSTDIR\bin" "/M=${uninstx} /S=0B /G=0" "" $4 $1 $2 $3 ; get size - uninstaller
  ${If} ${Errors}
    SetErrors
  ${EndIf}
  ${GetSizeOnDisk} "$INSTDIR\shortcut" "/M=*.lnk /S=0B /G=0" "" $5 $1 $2 $3 ; get size - shortcuts
  ${If} ${Errors}
    SetErrors
  ${EndIf}
  ${GetSizeOnDisk} "$INSTDIR" "/M=jtssjar.jnlp /S=0B /G=0" "" $6 $1 $2 $3 ; get size - java file
  ${If} ${Errors}
    SetErrors
  ${EndIf}
  ; subtract estimated size
  StrCpy $0 $BYTE_SIZE #
  ${IfNot} ${Errors}
    StrCpy ${TEMP1} ${S_SCF} # ; 7 (default)
    ${If} ${IsWin95} ; 95, 98, ME, NT4
    ${OrIf} ${IsWin98}
    ${OrIf} ${IsWinME}
    ${OrIf} ${IsWinNT4}
      IntOp ${TEMP1} ${TEMP1} + ${S_SC98}
    ${EndIf}
    ${If} ${AtLeastWin2000} ; 2000, XP, 2003
    ${AndIf} ${AtMostWin2003}
      IntOp ${TEMP1} ${TEMP1} + ${S_SCXP}
    ${EndIf}
    ${If} ${AtLeastWinVista} ; Vista, 2008
    ${AndIf} ${AtMostWin2008}
      IntOp ${TEMP1} ${TEMP1} + ${S_SCV}
    ${EndIf}
    ${If} ${AtLeastWin8} ; 2008R2, 8, 2012, 8.1, 2012R2
    ${AndIf} ${AtMostWin2012R2}
      IntOp ${TEMP1} ${TEMP1} + ${S_SC8}
    ${EndIf}
    ${If} ${AtLeastWin10} ; 10
      IntOp ${TEMP1} ${TEMP1} + ${S_SC10}
    ${EndIf}
    IntOp $0 $0 - ${TEMP1} ; shortcuts
    IntOp $0 $0 - ${S_JNLP} ; java
    !ifdef UNICODE
      StrCpy ${TEMP2} ${S_W} # ; unicode uninstaller
    !else
      StrCpy ${TEMP2} ${S_A} # ; ansi uninstaller
    !endif
    IntOp $0 $0 - ${TEMP2}
    ; add real size
    IntOp $0 $0 + $4
    IntOp $0 $0 + $5
    IntOp $0 $0 + $6
  ${EndIf}
  ClearErrors
  ; bytes to kilobytes
  IntOp $1 $0 % 1024
  IntOp $0 $0 / 1024 ; rounded down
  IntCmp $1 512 0 +2 0
  IntOp $0 $0 + 1 ; rounded up
  Push $0
  Call Separator
  Pop $7
  ${If} ${FileExists} "$INSTDIR\aforest\size.js"
    IntOp $1 ${T_0} - 2
    IntOp $2 ${A_0} - 1
    IntOp $3 $1 + $2
    StrCpy $8 "$3 pages. $2 pages" #
    FileOpen $9 "$INSTDIR\aforest\size.js" w
    IfErrors break
    FileWrite $9 "var obookpages = '$8';$\r$\nvar tigsetup = '${F_FILES} files ${D_FOLDERS} folders $7 Kb';"
    FileClose $9
    break:
    ClearErrors
  ${EndIf}
#  DetailPrint "$BYTE_SIZE - ${TEMP1} - ${S_JNLP} - ${TEMP2} + $5 + $6 + $4" ; check the sum
  ${If} $LANGUAGE == 1031
    DetailPrint "${F_FILES} Dateien | ${D_FOLDERS} Ordner | $7 Kb"
  ${Else}
    DetailPrint "${F_FILES} files | ${D_FOLDERS} folders | $7 Kb"
  ${EndIf}
  ClearErrors
  IntFmt $0 "0x%08X" $0
  StrCmp $ACCOUNT "0" +3
  WriteRegDword HKLM ${PRODUCT_UNINST_KEY} "EstimatedSize" $0
  Goto finito
  WriteRegDword HKCU ${PRODUCT_UNINST_KEY} "EstimatedSize" $0
  finito:
  ${GetTime} "/F" $7
  DetailPrint $7
SectionEnd

Function un.UpdateShellVarContext
  ${If} $X_ACCOUNT == 1
    SetShellVarContext all
  ${Else}
    SetShellVarContext current
  ${EndIf}
FunctionEnd

Function un.SystemDirsInit
  ${If} ${RunningX64}
    StrCpy $SYS_DIR "$WINDIR\SysWOW64" #
    StrCpy $SYS__DIR "$WINDIR\System32" #
  ${Else}
    StrCpy $SYS_DIR "$SYSDIR" #
  ${EndIf}
FunctionEnd

Function un.subfolders_remove
  ; parent folders have to be completely empty
  ${If} $PAR_NUM != 0
  ${AndIf} $PAR_NUM != ""
    ${GetParent} $R0 $R0
    RMDir $R0
    IntOp $PAR_NUM $PAR_NUM - 1
    call un.subfolders_remove
  ${EndIf}
FunctionEnd

Section Uninstall
  SetAutoClose false
  SetDetailsView show
  Call un.UpdateShellVarContext
  ${If} $X == 1
  ${AndIf} $DESK != 0
    Delete "$DESKTOP\$DTI.lnk"
  ${EndIf}
  ${If} $ICONS_GROUP != ""
    ${DirState} "$SMPROGRAMS\$ICONS_GROUP" $R0
    ${If} $R0 > 0
      Delete "$SMPROGRAMS\$ICONS_GROUP\*.lnk"
    ${AndIf} $R0 >= 0
      RMDir "$SMPROGRAMS\$ICONS_GROUP"
    ${EndIf}
  ${EndIf}
  Delete "$INSTDIR\*.*"
  ${If} $SPAWN != "/U"
    Delete "$INSTDIR\bin\${uninstx}"
  ${EndIf}
  RMDir /r "$INSTDIR\acrohome"
  RMDir /r "$INSTDIR\acroice"
  RMDir /r "$INSTDIR\aforest"
  RMDir /r "$INSTDIR\bigpix"
  ${If} $SPAWN != "/U"
    RMDir /r "$INSTDIR\bin"
  ${EndIf}
  RMDir /r "$INSTDIR\buttons"
  RMDir /r "$INSTDIR\clas1"
  RMDir /r "$INSTDIR\css"
  RMDir /r "$INSTDIR\flash"
  RMDir /r "$INSTDIR\graphics"
  RMDir /r "$INSTDIR\jazz1"
  RMDir /r "$INSTDIR\javacert"
  RMDir /r "$INSTDIR\help"
  RMDir /r "$INSTDIR\icons"
  RMDir /r "$INSTDIR\js"
  RMDir /r "$INSTDIR\menu"
  RMDir /r "$INSTDIR\midi"
  RMDir /r "$INSTDIR\mp3"
  RMDir /r "$INSTDIR\pix"
  RMDir /r "$INSTDIR\rock1"
  RMDir /r "$INSTDIR\shortcut"
  RMDir /r "$INSTDIR\thumbs"
  ${If} $SPAWN != "/U"
    RMDir $INSTDIR
    ${IfNot} ${FileExists} "$INSTDIR\*.*"
      StrCpy $R0 $INSTDIR #
      Call un.subfolders_remove
    ${EndIf}
  ${EndIf}

  ${If} $X_ACCOUNT == "1"
    Call un.SystemDirsInit
    StrCpy ${TEMP1} "$SYS_DIR\Macromed\Flash\FlashPlayerTrust" #
    Delete "${TEMP1}\tig$TIME"
    Delete "${TEMP1}\tig"
    RMDir ${TEMP1}
    ${If} ${RunningX64}
    ${AndIf} ${AtLeastWinVista}
      ${DisableX64FSRedirection}
      StrCpy $R1 "$SYS__DIR\Macromed\Flash\FlashPlayerTrust" #
      IfFileExists "$R1" 0 +4
      Delete "$R1\tig$TIME"
      Delete "$R1\tig"
      RMDir $R1
      ${EnableX64FSRedirection}
    ${EndIF}
    ${If} $X == "1"
      DeleteRegKey HKLM ${PRODUCT_UNINST_KEY}
    ${EndIf}
  ${Else}
    SetShellVarContext current
    ${If} $APPDATA != ""
      StrCpy $APP_DATA $APPDATA #
    ${Else}
      ReadRegStr $APP_DATA HKCU "${APP_DATA_KEY}" "App Data"
      ClearErrors
    ${EndIf}
    ${If} $APP_DATA != ""
      StrCpy ${TEMP1} "$APP_DATA\Macromedia\Flash Player\#Security\FlashPlayerTrust" #
      Delete "${TEMP1}\tig$TIME"
      Delete "${TEMP1}\tig"
      RMDir ${TEMP1}
      RMDir "$APP_DATA\Macromedia\Flash Player\#Security"
      RMDir "$APP_DATA\Macromedia\Flash Player"
      RMDir "$APP_DATA\Macromedia"
    ${EndIf}
    ${If} $X == 1
      DeleteRegKey HKCU ${PRODUCT_UNINST_KEY}
    ${EndIf}
  ${EndIf}
  Call un.remove_failed
SectionEnd

################################### unTIGbanner.nsh ####################################

; Tom’s Image Gallery 2.1 Setup Uninstall (banner) include (TN)
;--------------------------------

; Banner.dll plugin
ReserveFile /plugin "Banner.dll"

Function reinst_uninstall
  StrCmp $REM "keepcopy" done
  ${If} $LM_PREV_INST == "Y"
    SetShellVarContext all
    ReadRegStr $DESK HKLM ${PRODUCT_UNINST_KEY} "DeskTopIcon"
    ReadRegStr $TIME HKLM ${PRODUCT_UNINST_KEY} "TimeStamp"
    Call SystemDirsInit
    StrCpy ${TEMP1} "$SYS_DIR\Macromed\Flash\FlashPlayerTrust" #
    Delete "${TEMP1}\tig$TIME"
    Delete "${TEMP1}\tig"
    RMDir ${TEMP1}
    ${If} ${RunningX64}
    ${AndIf} ${AtLeastWinVista}
      ${DisableX64FSRedirection}
      StrCpy $R1 "$SYS__DIR\Macromed\Flash\FlashPlayerTrust" #
      IfFileExists "$R1" 0 +4
      Delete "$R1\tig$TIME"
      Delete "$R1\tig"
      RMDir $R1
      ${EnableX64FSRedirection}
    ${EndIF}
    DeleteRegKey HKLM ${PRODUCT_UNINST_KEY}
    ${If} $DESK == 1
      Delete "$DESKTOP\$DTI.lnk"
    ${EndIf}
    Delete "$SMPROGRAMS\$ICONS_PATH\*.lnk"
    RMDir /r "$SMPROGRAMS\$ICONS_PATH"
  ${Else}
    SetShellVarContext current
    ReadRegStr $DESK HKCU ${PRODUCT_UNINST_KEY} "DeskTopIcon"
    ReadRegStr $TIME HKCU ${PRODUCT_UNINST_KEY} "TimeStamp"
    ${If} $APPDATA != ""
      StrCpy $APP_DATA $APPDATA #
    ${Else}
      ReadRegStr $APP_DATA HKCU "${APP_DATA_KEY}" "App Data"
      ClearErrors
    ${EndIf}
    ${If} $APP_DATA != ""
      StrCpy ${TEMP1} "$APP_DATA\Macromedia\Flash Player\#Security\FlashPlayerTrust" #
      Delete "${TEMP1}\tig$TIME"
      Delete "${TEMP1}\tig"
      RMDir ${TEMP1}
      RMDir "$APP_DATA\Macromedia\Flash Player\#Security"
      RMDir "$APP_DATA\Macromedia\Flash Player"
      RMDir "$APP_DATA\Macromedia"
      DeleteRegKey HKCU ${PRODUCT_UNINST_KEY}
    ${EndIf}
    ${If} $DESK == 1
      Delete "$DESKTOP\T I G.lnk"
    ${EndIf}
    Delete "$SMPROGRAMS\$ICONS_PATH\*.lnk"
    RMDir /r "$SMPROGRAMS\$ICONS_PATH"
  ${EndIf}
  Banner::show /NOUNLOAD /set 76 "$(MESSAGE_BANNER_WAIT)" ""
  Banner::getWindow /NOUNLOAD ; contains the handle to the dialog window
  Pop $R1
  GetDlgItem $R2 $R1 1030
  Call UpdateShellVarContext
  Delete "$PATH\acrohome\*.*"
  Delete "$PATH\acroice\*.*"
  Delete "$PATH\aforest\*.*"
  Delete "$PATH\bigpix\*.*"
  Delete "$PATH\bin\*.*"
  Delete "$PATH\buttons\*.*"
  Delete "$PATH\clas1\*.*"
  Delete "$PATH\css\*.*"
  Delete "$PATH\flash\*.*"
  Delete "$PATH\graphics\*.*"
  Delete "$PATH\help\*.*"
  Delete "$PATH\icons\*.*"
  Delete "$PATH\jazz1\*.*"
  Delete "$PATH\javacert\*.*"
  Delete "$PATH\js\*.*"
  Delete "$PATH\menu\*.*"
  Delete "$PATH\midi\*.*"
  Delete "$PATH\mp3\*.*"
  Delete "$PATH\pix\*.*"
  Delete "$PATH\rock1\*.*"
  Delete "$PATH\shortcut\*.*"
  Delete "$PATH\thumbs\*.*"
  Delete "$PATH\*.*"
  RMDir /r "$PATH\acrohome"
  RMDir /r "$PATH\acroice"
  RMDir /r "$PATH\aforest"
  RMDir /r "$PATH\bigpix"
  RMDir /r "$PATH\bin"
  RMDir /r "$PATH\buttons"
  RMDir /r "$PATH\clas1"
  RMDir /r "$PATH\css"
  RMDir /r "$PATH\flash"
  RMDir /r "$PATH\graphics"
  RMDir /r "$PATH\help"
  RMDir /r "$PATH\icons"
  RMDir /r "$PATH\jazz1"
  RMDir /r "$PATH\js"
  RMDir /r "$PATH\menu"
  RMDir /r "$PATH\midi"
  RMDir /r "$PATH\mp3"
  RMDir /r "$PATH\pix"
  RMDir /r "$PATH\rock1"
  RMDir /r "$PATH\shortcut"
  RMDir /r "$PATH\thumbs"
  RMDir $PATH
  StrCmp $PAR_NUM "" endloop
    StrCpy $R0 $PATH #
    StrCpy $R3 $PAR_NUM #
  IfFileExists "$R0\*.*" endloop
  subfolders_remove:
  StrCmp $R3 0 endloop
  ${GetParent} $R0 $R0
  RMDir $R0
  IntOp $R3 $R3 - 1
  Goto subfolders_remove
  endloop:
  ${DirState} $PATH $R3
  Sleep 1200
  SendMessage $R2 ${WM_SETTEXT} 0 "STR:$(MESSAGE_BANNER_REMOVE_DONE)"
  Sleep 1200
  ShowWindow $R1 ${SW_HIDE} ; hide the dialog window
  Sleep 200
  IntCmp $R3 0 leave leave 0
  MessageBox MB_ICONEXCLAMATION|MB_OKCANCEL "$(MESSAGE_BANNER_REMOVE_FAIL)" /SD IDOK IDOK +4 IDCANCEL 0
    Sleep 500
    Banner::destroy
    Quit
  Sleep 500
  leave:
  Banner::destroy
  StrCpy $REM "banner" #
  StrCpy $INSTDIR $PATH #
  StrCpy $ICONS_GROUP $ICONS_PATH #
  done:
FunctionEnd

################################## unTIGsetupFull.nsh ##################################

; Tom’s Image Gallery 2.1 Setup Uninstall (full) include (TN)
;--------------------------------

; Initialize
!define MUI_CUSTOMFUNCTION_UNGUIINIT un.onGUIInit_func
; Welcome unpage
UninstPage custom un.nsDialogsWelcome ""
; Confirm unpage
!define MUI_PAGE_CUSTOMFUNCTION_PRE un.confirm
!insertmacro MUI_UNPAGE_CONFIRM
; Instfiles unpage
!insertmacro MUI_UNPAGE_INSTFILES
; Finish unpage
UninstPage custom un.nsDialogsFinish

;--------------------------------
; Functions

; Welcome UnPage
Function un.nsDialogsWelcome
  Call un.spawn_abort
  StrCmp $SPAWN "\U" +2
  File "/oname=$PLUGINSDIR\modern-wizard.bmp" "${LOCAL}tigwsu.bmp"
  Call un.HideControls
  nsDialogs::Create 1044
  Pop $DIALOG
  ${If} $LANGUAGE == 1031
  nsDialogs::SetRTL 0
  ${NSD_CreateLabel} 234u 16u 95u 80u "$(M_UNTEXT_WELCOME_INFO_TITLE)"
  ${Else}
  nsDialogs::SetRTL 1
  ${NSD_CreateLabel} 10u 16u 93u 80u "$(M_UNTEXT_WELCOME_INFO_TITLE)"
  ${EndIf}
  Pop $1
  nsDialogs::SetRTL 0
  ${NSD_CreateLabel} 58u 166u 221u 24u "$(M_UNTEXT_WELCOME_INFO_TEXT)"
  Pop $2
  ${NSD_CreateBitmap} 0 0 331u 193u ""
  Pop $IMAGECTL
  ${NSD_SetStretchedImage} $IMAGECTL "$PLUGINSDIR\modern-wizard.bmp" $IMAGE
  SetCtlColors $DIALOG "" 0xb4c6ff
  ${If} $LANGUAGE == 1031
  CreateFont $R1 "Verdana" 12 700 ; font size German title
  ${Else}
  CreateFont $R1 "Verdana" 16 700 ; font size English title
  ${EndIf}
  SendMessage $1 ${WM_SETFONT} $R1 0
  SetCtlColors $1 0x4f5235 transparent
  SetCtlColors $2 0x4f5235 transparent
  nsDialogs::Show
  Call un.ShowControls
  ${NSD_FreeImage} $IMAGE
FunctionEnd

Function un.spawn_abort
  ${If} $SPAWN == "/U"
    Abort
  ${EndIf}
FunctionEnd

Function un.HideControls
  LockWindow on
  GetDlgItem $0 $HWNDPARENT 1028
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 1256
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 1035
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 1037
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 1038
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 1039
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 1045
  ShowWindow $0 ${SW_NORMAL}
  LockWindow off
FunctionEnd

Function un.ShowControls
  LockWindow on
  GetDlgItem $0 $HWNDPARENT 1028
  ShowWindow $0 ${SW_NORMAL}
  GetDlgItem $0 $HWNDPARENT 1256
  ShowWindow $0 ${SW_NORMAL}
  GetDlgItem $0 $HWNDPARENT 1035
  ShowWindow $0 ${SW_NORMAL}
  GetDlgItem $0 $HWNDPARENT 1037
  ShowWindow $0 ${SW_NORMAL}
  GetDlgItem $0 $HWNDPARENT 1038
  ShowWindow $0 ${SW_NORMAL}
  GetDlgItem $0 $HWNDPARENT 1039
  ShowWindow $0 ${SW_NORMAL}
  GetDlgItem $0 $HWNDPARENT 1045
  ShowWindow $0 ${SW_HIDE}
  LockWindow off
FunctionEnd

; Confirm UnPage
Function un.confirm
  StrCmp $SPAWN "/U" 0 done
  GetDlgItem $3 $HWNDPARENT 3 ; Back button
  LockWindow on
  ShowWindow $3 ${SW_HIDE} ; hide 'Back'
  LockWindow off
  done:
FunctionEnd

Function un.remove_failed
  StrCpy $R2 "" # ; clear list
  StrCpy $R3 0 # ; set count
  ${If} ${FileExists} "$INSTDIR\*.*"
    ClearErrors
    Sleep 500 ; wait before ${Locate}
    ${Locate} $INSTDIR "/L=F" "un.populate_list"
    ClearErrors
    ${If} $R3 > 0
      DetailPrint "---------------------------"
      IntCmp $R3 1 0 0 +3
      DetailPrint "     $(DETAIL_REMOVED)"
      Goto +2
      DetailPrint "     $(DETAIL_REMOVED_S)"
      DetailPrint "###########################"
      DetailPrint ""
    ${Endif}
  ${EndIf}
FunctionEnd

Function un.populate_list ; files that were not removed
  ClearErrors
  StrCpy $R1 $R9 # ; Locate returns R9
  StrCmp $R1 "$INSTDIR\bin\${uninstx}" end ; exclude uninstaller
  SetDetailsPrint listonly
  StrCmp $R3 0 0 +5
  DetailPrint ""
  DetailPrint "###########################"
  DetailPrint "$(DETAIL_ERRORS)"
  DetailPrint "---------------------------"
  DetailPrint $R1
  SetDetailsPrint textonly
  IntOp $R3 $R3 + 1
  end:
  Push $0
FunctionEnd

; Finish UnPage
Function un.nsDialogsFinish
  Call un.spawn_abort
  Call un.HideControls
  ${If} $LANGUAGE == 1031
    StrCpy $R1 17 #
    StrCpy $R2 322 #
  ${Else}
    StrCpy $R1 66 #
    StrCpy $R2 269 #
  ${EndIf}
  GetDlgItem $R0 $HWNDPARENT 1
  ${NSD_SetText} $R0 "$(M_BUTTONTEXT_FINISH)"
  nsDialogs::Create 1044
  Pop $DIALOG
  nsDialogs::SetRTL 0
  ${NSD_CreateLabel} 58u 166u 221u 24u "$(M_UNTEXT_FINISH_INFO_TEXT)"
  Pop $1
  ${NSD_CreateBitmap} 0 0 331u 193u ""
  Pop $IMAGECTL
  ${NSD_SetStretchedImage} $IMAGECTL "$PLUGINSDIR\fmodern-wizard.bmp" $IMAGE
  SetCtlColors $DIALOG "" 0xb4c6ff
  SetCtlColors $1 0x4f5235 transparent
  nsDialogs::Show
  ${NSD_FreeImage} $IMAGE
FunctionEnd

Function un.ReadCustomData
  ; arguments
  Exch $R1  ; custom data magic value
  ; locals
  Push $1   ; file name or (later) file handle
  Push $2   ; current trial offset
  Push $3   ; current trial string (which will match R1 when custom data is found)
  Push $4   ; length of $R1

  FileOpen $1 "$INSTDIR\${uninstx}" r

  ; change 512 here to, e.g., 2048 to scan the last 2Kb of EXE file
  IntOp $2 0 - 512
  StrLen $4 $R1

loop:
  FileSeek $1 $2 END
  FileRead $1 $3 $4
  StrCmp $3 $R1 found
  IntOp $2 $2 + 1
  IntCmp $2 0 loop loop

  StrCpy $R1 ""
  goto fin

found:
  IntOp $2 $2 + $4
  FileSeek $1 $2 END
  FileRead $1 $3
  StrCpy $R1 $3

fin:
  FileClose $1
  Pop $4
  Pop $3
  Pop $2
  Pop $1
  Exch $R1
FunctionEnd

Function un.trim
  ${StrStrRight} $1 ";" $3
  StrLen $2 $3
  IntOp $2 $2 + 1
  StrCpy $1 $1 -$2
FunctionEnd

Function un.ParseCustomData
  Push "31904101:"
  Call un.ReadCustomData
  Pop $1
  Call un.trim
    StrCpy $X $3 #
  Call un.trim
    StrCpy $X_ACCOUNT $3 #
  Call un.trim
    StrCpy $X_PROFILE $3 #
  Call un.trim
    StrCpy $TIME $3 #
  Call un.trim
    StrCpy $PAR_NUM $3 #
  Call un.trim
    StrCpy $ICONS_GROUP $3 #
  Call un.trim
    StrCpy $LANGUAGE $3 #
  Call un.trim
    StrCpy $DESK $3 #
  Call un.trim
    StrCpy $PATH $3 #
;  MessageBox MB_OK "Custom data: $X $X_ACCOUNT $X_PROFILE $TIME $PAR_NUM $ICONS_GROUP $LANGUAGE $DESK $PATH"
FunctionEnd

Function un.onInit
  ; Re-locate temp folder
  !ifdef PLUGINSDIR_APPDATA
    ${If} ${SysDllAtLeastWinXPSP2}
      GetTempFileName $0
      ${StrStrRight} $0 "\" $0
        StrCpy $0 $0 -4 #
      UnsafeStrCpy $pluginsdir "$localappdata\${uninst}$0"
      CreateDirectory $pluginsdir
    ${EndIf}
  !endif
  StrCpy $SPAWN $CMDLINE "" -2
  StrCpy $WIN_V 0 #
  ${If} ${AtLeastWinVista}
    StrCpy $WIN_V 5 #
  ${EndIf}
  ; Accounts and Versions
  UserInfo::GetAccountType
  Pop $R0
  ${Select} $R0
    ${Case2} "Admin" "Power"
      StrCpy $ACCOUNT 1 #
    ${Case} "User"
      StrCpy $ACCOUNT 0 #
    ${CaseElse}
      StrCpy $WIN_V "N" #
  ${EndSelect}
  ${If} $WIN_V == 5
  ${AndIf} $ACCOUNT == 1
    StrCpy $WIN_V 6 #
    StrCpy $ACCOUNT 2 #
  ${EndIf}
  StrCmp $WIN_V "N" abort
  IntCmp $ACCOUNT 1 reg_test_admin reg_test_user reg_test_admin

  ; Registry Access
  reg_test_user:
  ReadRegStr $PATH HKCU ${PRODUCT_UNINST_KEY} "App Path"
  IfErrors exe_read
  IfFileExists "$PATH\*.*" 0 exe_read
  ReadRegStr $UNINSTSTR HKCU ${PRODUCT_UNINST_KEY} "UninstallString"
  IfErrors exe_read
    StrCpy $UNINST "$INSTDIR\${uninstx}" #
  StrCmp $UNINST $UNINSTSTR reg_read_user exe_read

  reg_test_admin:
  ReadRegStr $PATH HKLM ${PRODUCT_UNINST_KEY} "App Path"
  IfErrors redirect
  IfFileExists "$PATH\*.*" 0 redirect
  ReadRegStr $UNINSTSTR HKLM ${PRODUCT_UNINST_KEY} "UninstallString"
  IfErrors redirect continue
  redirect:
  ClearErrors
  StrCmp $WIN_V 0 exe_read reg_test_user
  continue:
    StrCpy $UNINST "$INSTDIR\${uninstx}" #
  StrCmp $UNINST $UNINSTSTR reg_read_admin
  StrCmp $WIN_V 0 exe_read reg_test_user

  ; Read Registry
  reg_read_user:
  ClearErrors
  ReadRegStr $LANG HKCU ${PRODUCT_UNINST_KEY} "Language"
    StrCpy $LANGUAGE $LANG #
  ReadRegStr $INSTDIR HKCU ${PRODUCT_UNINST_KEY} "App Path"
  ReadRegStr $DESK HKCU ${PRODUCT_UNINST_KEY} "DeskTopIcon"
  ReadRegStr $TIME HKCU ${PRODUCT_UNINST_KEY} "TimeStamp"
  ReadRegStr $PAR_NUM HKCU ${PRODUCT_UNINST_KEY} "SubFolder"
  ReadRegStr $ICONS_GROUP HKCU ${PRODUCT_UNINST_KEY} "StartMenuDir"
    StrCpy $DTI "T I G" #
    StrCpy $X_ACCOUNT 0 #
    StrCpy $ACCOUNT 0 #
    StrCpy $X 1 #
  Goto plug

  reg_read_admin:
  ClearErrors
  ReadRegStr $LANG HKLM ${PRODUCT_UNINST_KEY} "Language"
    StrCpy $LANGUAGE $LANG #
  ReadRegStr $INSTDIR HKLM ${PRODUCT_UNINST_KEY} "App Path"
  ReadRegStr $DESK HKLM ${PRODUCT_UNINST_KEY} "DeskTopIcon"
  ReadRegStr $TIME HKLM ${PRODUCT_UNINST_KEY} "TimeStamp"
  ReadRegStr $PAR_NUM HKLM ${PRODUCT_UNINST_KEY} "SubFolder"
  ReadRegStr $ICONS_GROUP HKLM ${PRODUCT_UNINST_KEY} "StartMenuDir"
  ReadRegStr $X_ACCOUNT HKLM ${PRODUCT_UNINST_KEY} "InstallType"
  ${If} $X_ACCOUNT == 1
    StrCpy $DTI "T.I.G." #
  ${Else}
    StrCpy $DTI "T I G" #
  ${EndIf}
    StrCpy $ACCOUNT 1 #
    StrCpy $X 1 #
  Goto plug

  exe_read: ; self-uninstall option - read string in file
  ClearErrors
  ${GetUser} $MY_PROFILE
  Call un.ParseCustomData
  IfErrors abort
  IfFileExists "$PATH\*.*" 0 abort
    StrCpy $INSTDIR $PATH #
  ${If} $ACCOUNT == 2
    StrCpy $ACCOUNT $X_ACCOUNT #
  ${EndIf}
  ; ACCOUNT 1 | X_ACCOUNT 1 | goto plug
  ; ACCOUNT 1 | X_ACCOUNT 0 | $X_PROFILE = $MY_PROFILE | goto plug
  ; ACCOUNT 1 | X_ACCOUNT 0 | $X_PROFILE ! $MY_PROFILE | goto abort (USER message)
  ; ACCOUNT 0 | X_ACCOUNT 1 | goto abort (UAC message)
  ; ACCOUNT 0 | X_ACCOUNT 0 | $X_PROFILE = $MY_PROFILE | goto plug
  ; ACCOUNT 0 | X_ACCOUNT 0 | $X_PROFILE ! $MY_PROFILE | goto abort (USER message)
  StrCmp $ACCOUNT 0 uac
  ReadRegStr $R0 HKLM ${PRODUCT_UNINST_KEY} "App Path"
  ${If} $R0 == $INSTDIR
    StrCpy $DTI "T.I.G." #
    StrCpy $X 1 # ; remove desktop icon + registry entries
  ${EndIf}
  StrCmp $X_ACCOUNT 1 plug profile
  uac:
  ReadRegStr $R0 HKCU ${PRODUCT_UNINST_KEY} "App Path"
  ${If} $R0 == $INSTDIR
    StrCpy $DTI "T I G" #
    StrCpy $X 1 # ; remove desktop icon + registry entries
  ${EndIf}
  StrCmp $X_ACCOUNT 0 profile
    StrCpy $R2 "uac" #
  Goto abort
  profile:
  StrCmp $X_PROFILE "" abort
  StrCmp $X_PROFILE $MY_PROFILE plug
    StrCpy $R2 "profile" #
  Goto abort

  ; Temporary Folder
  plug:
  !ifdef PLUGINSDIR_APPDATA
    ${IfNot} ${SysDllAtLeastWinXPSP2}
      InitPluginsDir
    ${EndIf}
  !else
    InitPluginsDir
  !endif
  SetOutPath "$PLUGINSDIR"
  ReserveFile /plugin "nsDialogs.dll"
  ReserveFile /plugin "System.dll"
  ReserveFile /plugin "UserInfo.dll"
  ReserveFile "${LOCAL}tighsu.bmp"
  ReserveFile "${LOCAL}tigfsu.bmp"
  File "/oname=$PLUGINSDIR\fmodern-wizard.bmp" "${LOCAL}tigfsu.bmp"
  ReserveFile "${LOCAL}tigwsu.bmp"
  SetOutPath "$TEMP"
  Goto done

  abort:
  ClearErrors
  ${If} $SPAWN != "/U"
    Call un.onUnInstFailed
  ${EndIf}
  done:
FunctionEnd

Function un.onGUIInit_func
  GetDlgItem $R0 $HWNDPARENT 1038
  SetCtlColors $R0 0x4f5235 0xfffff2
  GetDlgItem $R0 $HWNDPARENT 1037
  SetCtlColors $R0 0x4f5235 0xfffff2
  ; Header (title font)
  CreateFont $R1 "Verdana" 10 700
  SendMessage $R0 ${WM_SETFONT} $R1 0
  GetDlgItem $R0 $HWNDPARENT 1028
  SendMessage $R0 ${WM_SETTEXT} 1 "STR:"
  GetDlgItem $R0 $HWNDPARENT 1256
  SendMessage $R0 ${WM_SETTEXT} 1 "STR:"
  GetDlgItem $R0 $HWNDPARENT 2256
  SendMessage $R0 ${WM_SETTEXT} 1 "STR:Tom’s Image Gallery"
  GetDlgItem $R0 $HWNDPARENT 3256
  SendMessage $R0 ${WM_SETTEXT} 1 "STR:${PRODUCT_COPYRIGHT}"
FunctionEnd

; Post-Uninstall
Function un.onUnInstFailed
  ${If} $R2 == "profile"
    MessageBox MB_ICONSTOP|MB_OK|MB_DEFBUTTON1 "$(MESSAGE_UNABORT_PROFILE)" /SD IDOK IDOK quit
  ${ElseIf} $R2 == "uac"
    MessageBox MB_ICONSTOP|MB_OK|MB_DEFBUTTON1 "$(MESSAGE_UNABORT_UAC)" /SD IDOK IDOK quit
  ${ElseIf} $WIN_V == "N"
    MessageBox MB_ICONSTOP|MB_OK|MB_DEFBUTTON1 "$(MESSAGE_UNABORT_N)" /SD IDOK IDOK quit
  ${Else}
    MessageBox MB_ICONSTOP|MB_OK|MB_DEFBUTTON1 "$(MESSAGE_UNABORT)" /SD IDOK IDOK quit
  ${EndIf}
  quit:
  Quit
FunctionEnd

################################# TIGpassword.nsh #################################

; Tom’s Image Gallery 2.1 Setup Password include (TN)
;--------------------------------

!define MakePass "!insertmacro MakePass"
!define CheckPass "!insertmacro CheckPass"
!define CompileTasks "!insertmacro CompileTasks"
!define CompileCleanUp "!insertmacro CompileCleanUp"
!ifdef UNICODE
  !define 7z "C:\Program Files\7-Zip\7z.exe" ; 15.12
!else
  !define 7z "C:\Program Files\7-Zip 9.20\7z.exe"
!endif
!ifndef ResHacker
  !define ResHacker "${ABSDIR}\Resource Hacker\ResourceHacker.exe"
!endif
!ifndef upx
  !define upx "${ABSDIR}\UPX\upx.exe"
!endif

; Password - @compile-time
!macro MakePass
  !ifndef IV
    !system 'vector.exe' ; initial (random) vector
    !define /file IV iv.enc
#    !system 'userkey.exe' ; uncomment this line to create a new key
    !define /file UK uk.enc
    !system 'md5 -generate -d${UK}${IV} -l -o${LOCAL}${NSIDIR}\pw.enc'
    !define /file PW ${LOCAL}${NSIDIR}\pw.enc
  !endif
  StrCpy $PASSWORD ${PW} #
!macroend

; Password - @runtime, if "PASS_ON" is enabled
!macro CheckPass
  StrCpy $3 0
  loop:
  IntOp $3 $3 + 1
  IntCmp $3 100 0 0 incorrect
  md5dll::GetMD5String "${UK}$3"
  Pop $2
  StrCpy $2 $2 16 -24
  StrCmp ${TEMP1} $2 0 loop
  md5dll::GetMD5String ${UK}${IV}
  Pop ${TEMP1}
  incorrect:
!macroend

!macro CompileTasks
  !cd ${SRCDIR}
  !system 'copy berlinerv.exe $%TEMP%\berliner.exe'

  ; 7-Zip self-extracting archive (Igor Pavlov) - password encrypted
  !system '"${7z}" a -sfx -t7z -m0=lzma2 -p${PW} -mmt8 -y htmlexev.exe $%TEMP%\berliner.exe'
  !system '"${7z}" a -sfx -t7z -m0=lzma2 -p${PW} -mmt8 -y htmlexe.exe berliner.exe'
  !system '"${7z}" a -sfx -t7z -m0=lzma2 -p${PW} -mmt8 -y html.exe text*.htm add*.htm \
  mo_t*.htm mo_a*.htm quotes.htm exhibit.htm magic.htm impo.htm voyeur.htm gent.htm'
  !system '"${7z}" a -sfx -t7z -m0=lzma2 -p${PW} -mmt8 -y .\acroice\pdf.exe .\acroice\*.pdf'
  !system '"${7z}" a -sfx -t7z -m0=lzma2 -p${PW} -mmt8 -y .\acrohome\pdf.exe .\acrohome\*.pdf'

  ; swap icon resources
#  !execute '"${ResHacker}" -modify "htmlexev.exe", "htmlexev.exe", "${ABSDIR}\instx.ico", icongroup, 101, 1033'
#  !execute '"${ResHacker}" -modify "htmlexe.exe", "htmlexe.exe", "${ABSDIR}\instx.ico", icongroup, 101, 1033'
#  !execute '"${ResHacker}" -modify "html.exe", "html.exe", "${ABSDIR}\instx.ico", icongroup, 101, 1033'
#  !execute '"${ResHacker}" -modify "${SRCDIR}\acroice\pdf.exe", "${SRCDIR}\acroice\pdf.exe", "${ABSDIR}\instx.ico", icongroup, 101, 1033'
#  !execute '"${ResHacker}" -modify "${SRCDIR}\acrohome\pdf.exe", "${SRCDIR}\acrohome\pdf.exe", "${ABSDIR}\instx.ico", icongroup, 101, 1033'

  ; add manifest for compatibility + upx header compression
  !execute '"${ResHacker}" -add "htmlexev.exe", "htmlexev.exe", "${ABSDIR}\Key\sfxmanifest", 24, 1, 1033'
  !execute '"${upx}" -9 "htmlexev.exe"'
  !execute '"${ResHacker}" -add "htmlexe.exe", "htmlexe.exe", "${ABSDIR}\Key\sfxmanifest", 24, 1, 1033'
  !execute '"${upx}" -9 "htmlexe.exe"'
  !execute '"${ResHacker}" -add "html.exe", "html.exe", "${ABSDIR}\Key\sfxmanifest", 24, 1, 1033'
  !execute '"${upx}" -9 "html.exe"'
  !execute '"${ResHacker}" -add "${SRCDIR}\acroice\pdf.exe", "${SRCDIR}\acroice\pdf.exe", "${ABSDIR}\Key\sfxmanifest", 24, 1, 1033'
  !execute '"${upx}" -9 "${SRCDIR}\acroice\pdf.exe"'
  !execute '"${ResHacker}" -add "${SRCDIR}\acrohome\pdf.exe", "${SRCDIR}\acrohome\pdf.exe", "${ABSDIR}\Key\sfxmanifest", 24, 1, 1033'
  !execute '"${upx}" -9 "${SRCDIR}\acrohome\pdf.exe"'
  
  ReserveFile "html.exe"
  ReserveFile "htmlexev.exe"
  ReserveFile "htmlexe.exe"
  ReserveFile "acroice\pdf.exe"
  ReserveFile "acrohome\pdf.exe"

  !delfile $%TEMP%\berliner.exe
  !cd ${ABSDIR}\${NSIDIR}
!macroend

!macro CompileCleanUp ; (afterward)
  !delfile "${SRCDIR}\html.exe"
  !delfile "${SRCDIR}\htmlexev.exe"
  !delfile "${SRCDIR}\htmlexe.exe"
  !delfile "${SRCDIR}\acroice\pdf.exe"
  !delfile "${SRCDIR}\acrohome\pdf.exe"
!macroend

################################## TIGmacros.nsh ##################################

; Tom’s Image Gallery 2.1 Setup Macros include (TN)
;--------------------------------
/*

 FileFunction=[Locate|GetSizeOnDisk|DirState|GetParent|GetRoot|GetUser|
               GetUserDefaultLang|GetTime|StrStrRight]

*/
;_____________________________________________________________________________
;
;                         Macros
;_____________________________________________________________________________
;
; Change log window verbosity (default: 3=no script)
;
; Example:
; !include "TIGmacros.nsh"
; !insertmacro DirState
; ${FILEFUNC_VERBOSE} 4   # all verbosity
; !insertmacro GetParent
; ${FILEFUNC_VERBOSE} 3   # no script

!include Util.nsh ; for "CallArtificialFunction"

!verbose push
!verbose 3
!ifndef _FILEFUNC_VERBOSE
    !define _FILEFUNC_VERBOSE 3
!endif
!verbose ${_FILEFUNC_VERBOSE}
!define FILEFUNC_VERBOSE `!insertmacro FILEFUNC_VERBOSE`
!verbose pop

!macro FILEFUNC_VERBOSE _VERBOSE
    !verbose push
    !verbose 3
    !undef _FILEFUNC_VERBOSE
    !define _FILEFUNC_VERBOSE ${_VERBOSE}
    !verbose pop
!macroend

!macro LocateCall _PATH _OPTIONS _FUNC
    !verbose push
    !verbose ${_FILEFUNC_VERBOSE}
    Push $0
    Push `${_PATH}`
    Push `${_OPTIONS}`
    GetFunctionAddress $0 `${_FUNC}`
    Push `$0`
    ${CallArtificialFunction} Locate_
    Pop $0
    !verbose pop
!macroend

!macro GetSizeOnDiskCall _PATH _OPTIONS _FILESYSTEM _RESULT1 _RESULT2 _RESULT3 _RESULT4
    !verbose push
    !verbose ${_FILEFUNC_VERBOSE}
    Push `${_PATH}`
    Push `${_OPTIONS}`
    Push `${_FILESYSTEM}` ; volume block size
    ${CallArtificialFunction} GetSizeOnDisk_
    Pop ${_RESULT1}
    Pop ${_RESULT2}
    Pop ${_RESULT3}
    Pop ${_RESULT4}
    !verbose pop
!macroend

!macro DirStateCall _PATH _RESULT
    !verbose push
    !verbose ${_FILEFUNC_VERBOSE}
    Push `${_PATH}`
    ${CallArtificialFunction} DirState_
    Pop ${_RESULT}
    !verbose pop
!macroend

!macro GetParentCall _PATHSTRING _RESULT
    !verbose push
    !verbose ${_FILEFUNC_VERBOSE}
    Push `${_PATHSTRING}`
    ${CallArtificialFunction} GetParent_
    Pop ${_RESULT}
    !verbose pop
!macroend

!macro GetRootCall _FULLPATH _RESULT
    !verbose push
    !verbose ${_FILEFUNC_VERBOSE}
    Push `${_FULLPATH}`
    ${CallArtificialFunction} GetRoot_
    Pop ${_RESULT}
    !verbose pop
!macroend

!macro GetUserCall _PROFILE
    !verbose push
    !verbose ${_FILEFUNC_VERBOSE}
    ${CallArtificialFunction} GetUser_
    Pop ${_PROFILE}
    !verbose pop
!macroend

!macro GetUserDefaultLangCall _LID
    !verbose push
    !verbose ${_FILEFUNC_VERBOSE}
    ${CallArtificialFunction} GetUserDefaultLang_
    Pop ${_LID}
    !verbose pop
!macroend

!macro GetTimeCall _OPTIONS _TIME
    !verbose push
    !verbose ${_FILEFUNC_VERBOSE}
    Push `${_OPTIONS}`
    ${CallArtificialFunction} GetTime_
    Pop ${_TIME}
    !verbose pop
!macroend

!macro StrStrRightCall _STRING _SUBSTRING _NEWSTRING
    !verbose push
    !verbose ${_FILEFUNC_VERBOSE}
    Push `${_STRING}`
    Push `${_SUBSTRING}`
    ${CallArtificialFunction} StrStrRight_
    Pop ${_NEWSTRING}
    !verbose pop
!macroend

; ---------------
; Locate (FileFunc.nsh)

!define Locate `!insertmacro LocateCall`
!define un.Locate `!insertmacro LocateCall`

!macro Locate
!macroend

!macro un.Locate
!macroend

!macro Locate_
    !verbose push
    !verbose ${_FILEFUNC_VERBOSE}

    Exch $2
    Exch
    Exch $1
    Exch
    Exch 2
    Exch $0
    Exch 2
    Push $3
    Push $4
    Push $5
    Push $6
    Push $7
    Push $8
    Push $9
    Push $R6
    Push $R7
    Push $R8
    Push $R9
    ClearErrors

    StrCpy $3 ''
    StrCpy $4 ''
    StrCpy $5 ''
    StrCpy $6 ''
    StrCpy $7 ''
    StrCpy $8 0
    StrCpy $R7 ''

    StrCpy $R9 $0 1 -1
    StrCmp $R9 '\' 0 +3
    StrCpy $0 $0 -1
    goto -3
    IfFileExists '$0\*.*' 0 FileFunc_Locate_error

    FileFunc_Locate_option:
    StrCpy $R9 $1 1
    StrCpy $1 $1 '' 1
    StrCmp $R9 ' ' -2
    StrCmp $R9 '' FileFunc_Locate_sizeset
    StrCmp $R9 '/' 0 -4
    StrCpy $9 -1
    IntOp $9 $9 + 1
    StrCpy $R9 $1 1 $9
    StrCmp $R9 '' +2
    StrCmp $R9 '/' 0 -3
    StrCpy $R8 $1 $9
    StrCpy $R8 $R8 '' 2
    StrCpy $R9 $R8 '' -1
    StrCmp $R9 ' ' 0 +3
    StrCpy $R8 $R8 -1
    goto -3
    StrCpy $R9 $1 2
    StrCpy $1 $1 '' $9

    StrCmp $R9 'L=' 0 FileFunc_Locate_mask
    StrCpy $3 $R8
    StrCmp $3 '' +6
    StrCmp $3 'FD' +5
    StrCmp $3 'F' +4
    StrCmp $3 'D' +3
    StrCmp $3 'DE' +2
    StrCmp $3 'FDE' 0 FileFunc_Locate_error
    goto FileFunc_Locate_option

    FileFunc_Locate_mask:
    StrCmp $R9 'M=' 0 FileFunc_Locate_size
    StrCpy $4 $R8
    goto FileFunc_Locate_option

    FileFunc_Locate_size:
    StrCmp $R9 'S=' 0 FileFunc_Locate_gotosubdir
    StrCpy $6 $R8
    goto FileFunc_Locate_option

    FileFunc_Locate_gotosubdir:
    StrCmp $R9 'G=' 0 FileFunc_Locate_banner
    StrCpy $7 $R8
    StrCmp $7 '' +3
    StrCmp $7 '1' +2
    StrCmp $7 '0' 0 FileFunc_Locate_error
    goto FileFunc_Locate_option

    FileFunc_Locate_banner:
    StrCmp $R9 'B=' 0 FileFunc_Locate_error
    StrCpy $R7 $R8
    StrCmp $R7 '' +3
    StrCmp $R7 '1' +2
    StrCmp $R7 '0' 0 FileFunc_Locate_error
    goto FileFunc_Locate_option

    FileFunc_Locate_sizeset:
    StrCmp $6 '' FileFunc_Locate_default
    StrCpy $9 0
    StrCpy $R9 $6 1 $9
    StrCmp $R9 '' +4
    StrCmp $R9 ':' +3
    IntOp $9 $9 + 1
    goto -4
    StrCpy $5 $6 $9
    IntOp $9 $9 + 1
    StrCpy $1 $6 1 -1
    StrCpy $6 $6 -1 $9
    StrCmp $5 '' +2
    IntOp $5 $5 + 0
    StrCmp $6 '' +2
    IntOp $6 $6 + 0

    StrCmp $1 'B' 0 +3
    StrCpy $1 1
    goto FileFunc_Locate_default
    StrCmp $1 'K' 0 +3
    StrCpy $1 1024
    goto FileFunc_Locate_default
    StrCmp $1 'M' 0 +3
    StrCpy $1 1048576
    goto FileFunc_Locate_default
    StrCmp $1 'G' 0 FileFunc_Locate_error
    StrCpy $1 1073741824

    FileFunc_Locate_default:
    StrCmp $3 '' 0 +2
    StrCpy $3 'FD'
    StrCmp $4 '' 0 +2
    StrCpy $4 '*.*'
    StrCmp $7 '' 0 +2
    StrCpy $7 '1'
    StrCmp $R7 '' 0 +2
    StrCpy $R7 '0'
    StrCpy $7 'G$7B$R7'

    StrCpy $8 1
    Push $0
    SetDetailsPrint textonly

    FileFunc_Locate_nextdir:
    IntOp $8 $8 - 1
    Pop $R8

    StrCpy $9 $7 2 2
    StrCmp $9 'B0' +3
    GetLabelAddress $9 FileFunc_Locate_findfirst
    goto call
    DetailPrint 'Search in: $R8'

    FileFunc_Locate_findfirst:
    FindFirst $0 $R7 '$R8\$4'
    IfErrors FileFunc_Locate_subdir
    StrCmp $R7 '.' 0 FileFunc_Locate_dir
    FindNext $0 $R7
    StrCmp $R7 '..' 0 FileFunc_Locate_dir
    FindNext $0 $R7
    IfErrors 0 FileFunc_Locate_dir
    FindClose $0
    goto FileFunc_Locate_subdir

    FileFunc_Locate_dir:
    IfFileExists '$R8\$R7\*.*' 0 FileFunc_Locate_file
    StrCpy $R6 ''
    StrCmp $3 'DE' +4
    StrCmp $3 'FDE' +3
    StrCmp $3 'FD' FileFunc_Locate_precall
    StrCmp $3 'F' FileFunc_Locate_findnext FileFunc_Locate_precall
    FindFirst $9 $R9 '$R8\$R7\*.*'
    StrCmp $R9 '.' 0 +4
    FindNext $9 $R9
    StrCmp $R9 '..' 0 +2
    FindNext $9 $R9
    FindClose $9
    IfErrors FileFunc_Locate_precall FileFunc_Locate_findnext

    FileFunc_Locate_file:
    StrCmp $3 'FDE' +3
    StrCmp $3 'FD' +2
    StrCmp $3 'F' 0 FileFunc_Locate_findnext
    StrCpy $R6 0
    StrCmp $5$6 '' FileFunc_Locate_precall
    FileOpen $9 '$R8\$R7' r
    IfErrors +3
    FileSeek $9 0 END $R6
    FileClose $9
    System::Int64Op $R6 / $1
    Pop $R6
    StrCmp $5 '' +2
    IntCmp $R6 $5 0 FileFunc_Locate_findnext
    StrCmp $6 '' +2
    IntCmp $R6 $6 0 0 FileFunc_Locate_findnext

    FileFunc_Locate_precall:
    StrCpy $9 0
    StrCpy $R9 '$R8\$R7'

    call:
    Push $0
    Push $1
    Push $2
    Push $3
    Push $4
    Push $5
    Push $6
    Push $7
    Push $8
    Push $9
    Push $R7
    Push $R8
    StrCmp $9 0 +4
    StrCpy $R6 ''
    StrCpy $R7 ''
    StrCpy $R9 ''
    Call $2
    Pop $R9
    Pop $R8
    Pop $R7
    Pop $9
    Pop $8
    Pop $7
    Pop $6
    Pop $5
    Pop $4
    Pop $3
    Pop $2
    Pop $1
    Pop $0

    IfErrors 0 +3
    FindClose $0
    goto FileFunc_Locate_error
    StrCmp $R9 'StopLocate' 0 +3
    FindClose $0
    goto FileFunc_Locate_clearstack
    goto $9

    FileFunc_Locate_findnext:
    FindNext $0 $R7
    IfErrors 0 FileFunc_Locate_dir
    FindClose $0

    FileFunc_Locate_subdir:
    StrCpy $9 $7 2
    StrCmp $9 'G0' FileFunc_Locate_end
    FindFirst $0 $R7 '$R8\*.*'
    StrCmp $R7 '.' 0 FileFunc_Locate_pushdir
    FindNext $0 $R7
    StrCmp $R7 '..' 0 FileFunc_Locate_pushdir
    FindNext $0 $R7
    IfErrors 0 FileFunc_Locate_pushdir
    FindClose $0
    StrCmp $8 0 FileFunc_Locate_end FileFunc_Locate_nextdir

    FileFunc_Locate_pushdir:
    IfFileExists '$R8\$R7\*.*' 0 +3
    Push '$R8\$R7'
    IntOp $8 $8 + 1
    FindNext $0 $R7
    IfErrors 0 FileFunc_Locate_pushdir
    FindClose $0
    StrCmp $8 0 FileFunc_Locate_end FileFunc_Locate_nextdir

    FileFunc_Locate_error:
    SetErrors

    FileFunc_Locate_clearstack:
    StrCmp $8 0 FileFunc_Locate_end
    IntOp $8 $8 - 1
    Pop $R8
    goto FileFunc_Locate_clearstack

    FileFunc_Locate_end:
    SetDetailsPrint both
    Pop $R9
    Pop $R8
    Pop $R7
    Pop $R6
    Pop $9
    Pop $8
    Pop $7
    Pop $6
    Pop $5
    Pop $4
    Pop $3
    Pop $2
    Pop $1
    Pop $0

    !verbose pop
!macroend

; ---------------
; GetSizeOnDisk (modified "GetSize" - FileFunc.nsh - KiCHiK - Function "FindFiles")

!define GetSizeOnDisk `!insertmacro GetSizeOnDiskCall`
!define un.GetSizeOnDisk `!insertmacro GetSizeOnDiskCall`

!macro GetSizeOnDisk
!macroend

!macro un.GetSizeOnDisk
!macroend

; Usage: similar to "GetSize"

; For documentation, see the NSIS user manual: E.1.3 GetSize
; Four (not three) values are returned

; $var1     ; Result1: Size/Size on disk
; $var2     ; Result2: Sum of files
; $var3     ; Result3: Sum of directories
; $var4     ; Result4: Sum of compressed/sparse files

; Example: ${GetSizeOnDisk} "$INSTDIR" "/S=0K" "SOD" $0 $1 $2 $3
; DetailPrint "$1 file(s) | $2 folder(s) | $0 Kb | $3 compressed or sparse file(s)"

; Specifying 'SOD' (e.g. Size On Disk) toggles the $var1 result
; Output is logical size, if used, or physical size, if left empty ""
; The target volume's allocation unit size in bytes, the size of a
; cluster, for example '4096' bytes, if valid, can also be the input
; If neither 'SOD' nor a cluster size is specified, $var4 returns 0
; even where compressed and/or sparse files exist

; ${GetSizeOnDisk} can be used with Windows NT and Windows 2000
; When the volume is FAT32, FAT16 or an older file system, the result
; in $var1 reverts to physical size, although not incorrect

!macro GetSizeOnDisk_
    !verbose push
    !verbose ${_FILEFUNC_VERBOSE}

    Exch $2
    Exch 2
    Exch $0
    Exch
    Exch $1
    Push $3
    Push $4
    Push $5
    Push $6
    Push $7
    Push $8
    Push $9
    Push $R0
    Push $R1
    Push $R2
    StrCpy $R1 $2
    Push $R3
    Push $R4
    Push $R5
    Push $R6
    Push $R7
    Push $R8
    Push $R9
    ClearErrors

    StrCmp $R1 '' FileFunc_GetSize_path

    StrCpy $5 $0
    StrCpy $2 $0 2
    StrCmp $2 '\\' FileFunc_GetSize_Root_UNC
    StrCpy $3 $2 1 1
    StrCmp $3 ':' 0 FileFunc_GetSize_Root_empty
    StrCpy $5 $2
    goto FileFunc_GetSize_FileSystem

    FileFunc_GetSize_Root_UNC:
    StrCpy $3 1
    StrCpy $4 ''

    FileFunc_GetSize_Root_loop:
    IntOp $3 $3 + 1
    StrCpy $2 $5 1 $3
    StrCmp $2$4 '' FileFunc_GetSize_Root_empty
    StrCmp $2 '' +5
    StrCmp $2 '\' 0 FileFunc_GetSize_Root_loop
    StrCmp $4 '1' +3
    StrCpy $4 '1'
    goto FileFunc_GetSize_Root_loop
    StrCpy $5 $5 $3
    StrCpy $3 $5 1 -1
    StrCmp $3 '\' 0 FileFunc_GetSize_FileSystem

    FileFunc_GetSize_Root_empty:
    StrCpy $5 ''

    FileFunc_GetSize_FileSystem:
    System::Call 'Kernel32::GetVolumeInformation(t "$5\",t,i ${NSIS_MAX_STRLEN},*i,*i,*i,t.r2,i ${NSIS_MAX_STRLEN})i.r3'
    StrCmp $3 0 FileFunc_GetSize_FileSystem_error
    StrCpy $2 $2 3
    StrCmp $2 'FAT' FileFunc_GetSize_FileSystem_error
    StrCmp $R1 'SOD' 0 FileFunc_GetSize_path
    System::Call 'kernel32::GetDiskFreeSpace(t "$5\",*i0r2,*i0r3,,)'
    IntOp $R1 $2 * $3
    goto FileFunc_GetSize_path

    FileFunc_GetSize_FileSystem_error:
    StrCpy $R1 ''

    FileFunc_GetSize_path:
    StrCpy $R9 $0 1 -1
    StrCmp $R9 '\' 0 +3
    StrCpy $0 $0 -1
    goto -3
    IfFileExists '$0\*.*' 0 FileFunc_GetSize_error

    StrCpy $3 0
    StrCpy $4 ''
    StrCpy $5 ''
    StrCpy $6 ''
    StrCpy $8 0
    StrCpy $R3 ''
    StrCpy $R4 ''
    StrCpy $R5 ''

    FileFunc_GetSize_option:
    StrCpy $R9 $1 1
    StrCpy $1 $1 '' 1
    StrCmp $R9 ' ' -2
    StrCmp $R9 '' FileFunc_GetSize_sizeset
    StrCmp $R9 '/' 0 -4

    StrCpy $9 -1
    IntOp $9 $9 + 1
    StrCpy $R9 $1 1 $9
    StrCmp $R9 '' +2
    StrCmp $R9 '/' 0 -3
    StrCpy $8 $1 $9
    StrCpy $8 $8 '' 2
    StrCpy $R9 $8 '' -1
    StrCmp $R9 ' ' 0 +3
    StrCpy $8 $8 -1
    goto -3
    StrCpy $R9 $1 2
    StrCpy $1 $1 '' $9

    StrCmp $R9 'M=' 0 FileFunc_GetSize_size
    StrCpy $4 $8
    goto FileFunc_GetSize_option

    FileFunc_GetSize_size:
    StrCmp $R9 'S=' 0 FileFunc_GetSize_gotosubdir
    StrCpy $6 $8
    goto FileFunc_GetSize_option

    FileFunc_GetSize_gotosubdir:
    StrCmp $R9 'G=' 0 FileFunc_GetSize_error
    StrCpy $7 $8
    StrCmp $7 '' +3
    StrCmp $7 '1' +2
    StrCmp $7 '0' 0 FileFunc_GetSize_error
    goto FileFunc_GetSize_option

    FileFunc_GetSize_sizeset:
    StrCmp $6 '' FileFunc_GetSize_default
    StrCpy $9 0
    StrCpy $R9 $6 1 $9
    StrCmp $R9 '' +4
    StrCmp $R9 ':' +3
    IntOp $9 $9 + 1
    goto -4
    StrCpy $5 $6 $9
    IntOp $9 $9 + 1
    StrCpy $1 $6 1 -1
    StrCpy $6 $6 -1 $9
    StrCmp $5 '' +2
    IntOp $5 $5 + 0
    StrCmp $6 '' +2
    IntOp $6 $6 + 0

    StrCmp $1 'B' 0 +4
    StrCpy $1 1
    StrCpy $2 bytes
    goto FileFunc_GetSize_default
    StrCmp $1 'K' 0 +4
    StrCpy $1 1024
    StrCpy $2 Kb
    goto FileFunc_GetSize_default
    StrCmp $1 'M' 0 +4
    StrCpy $1 1048576
    StrCpy $2 Mb
    goto FileFunc_GetSize_default
    StrCmp $1 'G' 0 FileFunc_GetSize_error
    StrCpy $1 1073741824
    StrCpy $2 Gb

    FileFunc_GetSize_default:
    StrCmp $4 '' 0 +2
    StrCpy $4 '*.*'
    StrCmp $7 '' 0 +2
    StrCpy $7 '1'

    StrCpy $8 1
    Push $0
    SetDetailsPrint textonly

    FileFunc_GetSize_nextdir:
    IntOp $8 $8 - 1
    Pop $R8
    FindFirst $0 $R7 '$R8\$4'
    IfErrors FileFunc_GetSize_show
    StrCmp $R7 '.' 0 FileFunc_GetSize_dir
    FindNext $0 $R7
    StrCmp $R7 '..' 0 FileFunc_GetSize_dir
    FindNext $0 $R7
    IfErrors 0 FileFunc_GetSize_dir
    FindClose $0
    goto FileFunc_GetSize_show

    FileFunc_GetSize_dir:
    IfFileExists '$R8\$R7\*.*' 0 FileFunc_GetSize_file
    IntOp $R5 $R5 + 1
    goto FileFunc_GetSize_findnext

    FileFunc_GetSize_file:
    StrCpy $R6 0
    StrCmp $5$6 '' 0 +3
    IntOp $R4 $R4 + 1
    goto FileFunc_GetSize_findnext
    StrCmp $R1 '' FileFunc_GetSize_fileopen
    StrCpy $R0 0
    System::Call 'kernel32::GetFileAttributes(t "$R8\$R7")i .R2'
    StrCmp $R2 -1 FileFunc_GetSize_fileopen
    IntOp $R0 $R2 & 0x0800 ; compressed
    IntCmp $R0 0 0 0 FileFunc_GetSize_GetCompressed
    IntOp $R0 $R2 & 0x0200 ; sparse file
    IntCmp $R0 0 FileFunc_GetSize_fileopen
    FileFunc_GetSize_GetCompressed:
    System::Call 'kernel32::GetCompressedFileSize(t "$R8\$R7", i)i .R6'
    IntCmp $R6 4096 +2 0 +2
    StrCpy $R6 4096
    IntOp $3 $3 + 1 ; location contains compressed or sparse files
    goto FileFunc_GetSize_fileclose
    FileFunc_GetSize_fileopen:
    FileOpen $9 '$R8\$R7' r
    IfErrors FileFunc_GetSize_error
    FileSeek $9 0 END $R6
    FileClose $9
    FileFunc_GetSize_fileclose:
    StrCmp $5 '' +2
    IntCmp $R6 $5 0 FileFunc_GetSize_findnext
    StrCmp $6 '' +2
    IntCmp $R6 $6 0 0 FileFunc_GetSize_findnext
    IntOp $R4 $R4 + 1
    StrCmp $R1 '' FileFunc_GetSize_file_add
    StrCmp $R0 0 0 FileFunc_GetSize_file_add
    StrCpy $R0 $R1
    IntOp $R6 $R6 + $R0
    IntOp $R1 $R6 % $R0
    StrCmp $R1 0 0 +2
    StrCpy $R1 $R0
    IntOp $R2 $R0 - $R1
    IntOp $R6 $R6 - $R0
    IntOp $R6 $R6 + $R2
    StrCpy $R1 $R0
    FileFunc_GetSize_file_add:
    System::Int64Op $R3 + $R6
    Pop $R3

    FileFunc_GetSize_findnext:
    FindNext $0 $R7
    IfErrors 0 FileFunc_GetSize_dir
    FindClose $0

    FileFunc_GetSize_show:
    StrCmp $5$6 '' FileFunc_GetSize_nosize
    System::Int64Op $R3 / $1
    Pop $9
    DetailPrint 'Size:$9 $2  Files:$R4  Folders:$R5'
    goto FileFunc_GetSize_subdir
    FileFunc_GetSize_nosize:
    DetailPrint 'Files:$R4  Folders:$R5'

    FileFunc_GetSize_subdir:
    StrCmp $7 0 FileFunc_GetSize_preend
    FindFirst $0 $R7 '$R8\*.*'
    StrCmp $R7 '.' 0 FileFunc_GetSize_pushdir
    FindNext $0 $R7
    StrCmp $R7 '..' 0 FileFunc_GetSize_pushdir
    FindNext $0 $R7
    IfErrors 0 FileFunc_GetSize_pushdir
    FindClose $0
    StrCmp $8 0 FileFunc_GetSize_preend FileFunc_GetSize_nextdir

    FileFunc_GetSize_pushdir:
    IfFileExists '$R8\$R7\*.*' 0 +3
    Push '$R8\$R7'
    IntOp $8 $8 + 1
    FindNext $0 $R7
    IfErrors 0 FileFunc_GetSize_pushdir
    FindClose $0
    StrCmp $8 0 FileFunc_GetSize_preend FileFunc_GetSize_nextdir

    FileFunc_GetSize_preend:
    StrCmp $R3 '' FileFunc_GetSize_nosizeend
    System::Int64Op $R3 / $1
    Pop $R3
    FileFunc_GetSize_nosizeend:
    StrCpy $2 $R4
    StrCpy $1 $R5
    StrCpy $0 $R3
    goto FileFunc_GetSize_noerror

    FileFunc_GetSize_error:
    SetErrors
    StrCpy $0 ''
    StrCpy $1 ''
    StrCpy $2 ''
    StrCpy $3 ''
    goto FileFunc_GetSize_end

    FileFunc_GetSize_noerror:
    StrCmp $0 '' 0 +2
    StrCpy $0 0
    StrCmp $1 '' 0 +2
    StrCpy $1 0
    StrCmp $2 '' 0 +2
    StrCpy $2 0
    StrCmp $3 '' 0 +2
    StrCpy $3 0

    FileFunc_GetSize_end:
    SetDetailsPrint both
    Pop $R9
    Pop $R8
    Pop $R7
    Pop $R6
    Pop $R5
    Pop $R4
    Pop $R3
    Pop $R2
    Pop $R1
    Pop $R0
    Pop $9
    Pop $8
    Pop $7
    Pop $6
    Pop $5
    Pop $4
    Exch $3
    Exch 3
    Exch $2
    Exch
    Exch $1
    Exch 2
    Exch $0

    !verbose pop
!macroend

; ---------------
; DirState (FileFunc.nsh)
; (-1 = dir does not exist | 0 = dir is empty | 1 = dir is full)

!define DirState `!insertmacro DirStateCall`
!define un.DirState `!insertmacro DirStateCall`

!macro DirState
!macroend

!macro un.DirState
!macroend

!macro DirState_
    !verbose push
    !verbose ${_FILEFUNC_VERBOSE}

    Exch $0
    Push $1
    ClearErrors

    FindFirst $1 $0 '$0\*.*'
    IfErrors 0 +3
    StrCpy $0 -1
    goto FileFunc_DirState_end
    StrCmp $0 '.' 0 +4
    FindNext $1 $0
    StrCmp $0 '..' 0 +2
    FindNext $1 $0
    FindClose $1
    IfErrors 0 +3
    StrCpy $0 0
    goto FileFunc_DirState_end
    StrCpy $0 1

    FileFunc_DirState_end:
    Pop $1
    Exch $0

    !verbose pop
!macroend

; ---------------
; GetParent (FileFunc.nsh - sunjammer - Based on his Function "GetParent")

!define GetParent `!insertmacro GetParentCall`
!define un.GetParent `!insertmacro GetParentCall`

!macro GetParent
!macroend

!macro un.GetParent
!macroend

!macro GetParent_
    !verbose push
    !verbose ${_FILEFUNC_VERBOSE}

    Exch $0
    Push $1
    Push $2

    StrCpy $2 $0 1 -1
    StrCmp $2 '\' 0 +3
    StrCpy $0 $0 -1
    goto -3

    StrCpy $1 0
    IntOp $1 $1 - 1
    StrCpy $2 $0 1 $1
    StrCmp $2 '\' +2
    StrCmp $2 '' 0 -3
    StrCpy $0 $0 $1

    Pop $2
    Pop $1
    Exch $0

    !verbose pop
!macroend

; ---------------
; GetRoot (FileFunc.nsh - KiCHiK - Based on his Function "GetRoot")

!define GetRoot `!insertmacro GetRootCall`
!define un.GetRoot `!insertmacro GetRootCall`

!macro GetRoot
!macroend

!macro un.GetRoot
!macroend

!macro GetRoot_
    !verbose push
    !verbose ${_FILEFUNC_VERBOSE}

    Exch $0
    Push $1
    Push $2
    Push $3

    StrCpy $1 $0 2
    StrCmp $1 '\\' FileFunc_GetRoot_UNC
    StrCpy $2 $1 1 1
    StrCmp $2 ':' 0 FileFunc_GetRoot_empty
    StrCpy $0 $1
    goto FileFunc_GetRoot_end

    FileFunc_GetRoot_UNC:
    StrCpy $2 1
    StrCpy $3 ''

    FileFunc_GetRoot_loop:
    IntOp $2 $2 + 1
    StrCpy $1 $0 1 $2
    StrCmp $1$3 '' FileFunc_GetRoot_empty
    StrCmp $1 '' +5
    StrCmp $1 '\' 0 FileFunc_GetRoot_loop
    StrCmp $3 '1' +3
    StrCpy $3 '1'
    goto FileFunc_GetRoot_loop
    StrCpy $0 $0 $2
    StrCpy $2 $0 1 -1
    StrCmp $2 '\' 0 FileFunc_GetRoot_end

    FileFunc_GetRoot_empty:
    StrCpy $0 ''

    FileFunc_GetRoot_end:
    Pop $3
    Pop $2
    Pop $1
    Exch $0

    !verbose pop
!macroend

; ---------------
; GetUser

!define GetUser `!insertmacro GetUserCall`
!define un.GetUser `!insertmacro GetUserCall`

!macro GetUser
!macroend

!macro un.GetUser
!macroend

!macro GetUser_
    !verbose push
    !verbose ${_FILEFUNC_VERBOSE}

    Push $0
    Push $1
    Push $2
    System::Call 'advapi32::GetUserName(t .r0, *i ${NSIS_MAX_STRLEN} r1) i .r2'
    ; MessageBox MB_OK "User name: $0 | Number of characters: $1 | Return value (OK if non-zero): $2"
    ${If} $2 == 0
    StrCpy $1 '' #
    ${EndIf}
    Pop $2
    Pop $1
    Exch $0

    !verbose pop
!macroend

; ---------------
; GetUserDefaultLang

!define GetUserDefaultLang `!insertmacro GetUserDefaultLangCall`
!define un.GetUserDefaultLang `!insertmacro GetUserDefaultLangCall`

!macro GetUserDefaultLang
!macroend

!macro un.GetUserDefaultLang
!macroend

!macro GetUserDefaultLang_
    !verbose push
    !verbose ${_FILEFUNC_VERBOSE}

    Push $0
    System::Call 'kernel32::GetUserDefaultLangID() i .r0'
    ; If there is no perfect match, find a primary language match
    ${Select} $0
    ${Case5} 1031 2055 3079 4103 5127
    StrCpy $0 1031 # ; German
    ${Case5} 1033 2057 3081 4105 5129
    StrCpy $0 1033 # ; English
    ${Case5} 6153 7177 8201 9225 10249
    StrCpy $0 1033 #
    ${Case3} 11273 12297 13321
    StrCpy $0 1033 #
    ${Case3} 1036 2060 3084
    StrCpy $0 1036 # ; French
    ${Case3} 4108 5132 6156
    StrCpy $0 1036 #
    ${Case2} 1043 2067
    StrCpy $0 1043 # ; Dutch
    ${Case2} 1053 2077
    StrCpy $0 1053 # ; Swedish
    ${Case5} 1034 2058 3082 4106 5130
    StrCpy $0 1034 # ; Spanish
    ${Case5} 6154 7178 8202 9226 10250
    StrCpy $0 1034 #
    ${Case5} 11274 12298 13322 14346 15370
    StrCpy $0 1034 #
    ${Case5} 16394 17418 18442 19466 20490
    StrCpy $0 1034 #
    ${CaseElse}
    StrCpy $0 "" #
    ${EndSelect}
    Exch $0

    !verbose pop
!macroend

; ---------------
; GetTime

!define GetTime `!insertmacro GetTimeCall`
!define un.GetTime `!insertmacro GetTimeCall`

!macro GetTime
!macroend

!macro un.GetTime
!macroend

!macro GetTime_
    !verbose push
    !verbose ${_FILEFUNC_VERBOSE}

    Exch $R9
    Push $0
    Push $1
    Push $2
    Push $3
    Push $4
    Push $5
    Push $6
    Push $7
    ; option1 = S (STAMP) | option2 = F (FORMATTED)
    ClearErrors
    System::Call '*(&i2,&i2,&i2,&i2,&i2,&i2,&i2,&i2) i .r7'
    System::Call 'kernel32::GetLocalTime(i)i(r7)'
    System::Call '*$7(&i2,&i2,&i2,&i2,&i2,&i2,&i2,&i2)i(.r5,.r6,.r4,.r0,.r3,.r2,.r1,)'
    ; 0 day ; 1 seconds ; 2 minutes ; 3 hour ; 4 day of week name ; 5 year ; 6 month
    IntCmp $0 9 0 0 +2
    StrCpy $0 '0$0'
    IntCmp $1 9 0 0 +2
    StrCpy $1 '0$1'
    IntCmp $2 9 0 0 +2
    StrCpy $2 '0$2'
    IntCmp $3 9 0 0 +2
    StrCpy $3 '0$3'
    IntCmp $6 9 0 0 +2
    StrCpy $6 '0$6'
    StrCmp $R9 '/S' +2
    StrCmp $R9 '/F' +3
    StrCpy $R9 $0$6$5$3$2$1
    Goto +2
    StrCpy $R9 '$5-$6-$0 $3:$2:$1'
    Pop $7
    Pop $6
    Pop $5
    Pop $4
    Pop $3
    Pop $2
    Pop $1
    Pop $0
    Exch $R9

    !verbose pop
!macroend

; ---------------
; StrStrRight

!define StrStrRight `!insertmacro StrStrRightCall`
!define un.StrStrRight `!insertmacro StrStrRightCall`

!macro StrStrRight
!macroend

!macro un.StrStrRight
!macroend

!macro StrStrRight_
    !verbose push
    !verbose ${_FILEFUNC_VERBOSE}

    ; Search in a string from right to left
    ; Usage:
    ;   Push "this is a long ass string"
    ;   Push " ass"
    ;   Call (un.)StrStrRight
    ;   Pop $R0
    ;   ($R0 at this point is "ass string")
    Exch $R1 ; st=haystack,old$R1, $R1=needle
    Exch     ; st=old$R1,haystack
    Exch $R2 ; st=old$R1,old$R2, $R2=haystack
    Push $R3
    Push $R4
    Push $R5
    StrLen $R3 $R1
    StrLen $R4 $R2
    IntOp $R4 $R4 - 1
    strstr_loop:
    StrCpy $R5 $R2 $R3 $R4
    StrCmp $R5 $R1 strstr_done
    StrCmp $R5 "" strstr_done
    IntOp $R4 $R4 - 1
    Goto strstr_loop
    strstr_done:
    IntOp $R4 $R4 + 1
    StrCpy $R1 $R2 "" $R4
    Pop $R5
    Pop $R4
    Pop $R3
    Pop $R2
    Exch $R1

    !verbose pop
!macroend

################################## LanguageStrings.nsh ##################################

; Tom’s Image Gallery 2.1 Setup Language Strings include (TN)
;--------------------------------

!ifndef MUI_MODIFIED
; MUI 2 changes - English
LangString M_TEXT_LICENSE_TITLE ${LANG_ENGLISH} "License"
LangString M_TEXT_LICENSE_SUBTITLE ${LANG_ENGLISH} "Please review the license terms before installing the software."
LangString M_INNERTEXT_LICENSE_BOTTOM_CHECKBOX ${LANG_ENGLISH} "If you accept the terms of the agreement, click the \
check box below. You must accept the agreement to install $(^NameDA)."
LangString M_TEXT_DIRECTORY_TITLE ${LANG_ENGLISH} "Install Location"
LangString M_TEXT_STARTMENU_TITLE ${LANG_ENGLISH} "Shortcuts Folder"
LangString M_TEXT_STARTMENU_SUBTITLE ${LANG_ENGLISH} "Choose a Start Menu folder for the $(^NameDA) shortcuts."
; MUI 2 changes - German
LangString M_TEXT_LICENSE_TITLE ${LANG_GERMAN} "Lizenzabkommen"
LangString M_TEXT_LICENSE_SUBTITLE ${LANG_GERMAN} "Bitte lesen Sie die folgende Lizenzvereinbarung \
sorgfältig durch."
LangString M_INNERTEXT_LICENSE_BOTTOM_CHECKBOX ${LANG_GERMAN} "Falls Sie alle Bedingungen des Abkommens \
akzeptieren, aktivieren Sie das Kästchen. Sie müssen die Lizenzvereinbarungen anerkennen, um $(^NameDA) \
installieren zu können."
LangString M_TEXT_DIRECTORY_TITLE ${LANG_GERMAN} "Zielverzeichnis auswählen"
LangString M_TEXT_STARTMENU_TITLE ${LANG_GERMAN} "Startmenü-Ordner bestimmen"
LangString M_TEXT_STARTMENU_SUBTITLE ${LANG_GERMAN} "Bestimmen Sie einen Ordner für die Programmverknüpfungen."
!endif

;--------------------------------
; English

LangString M_TEXT_WELCOME_INFO_TITLE ${LANG_ENGLISH} "Welcome$\n$\rto the$\n$\r$(^NameDA) Setup"
LangString M_TEXT_WELCOME_INFO_TEXT ${LANG_ENGLISH} "Setup will guide you through the installation \
of $(^NameDA) on your computer.$\n$\rClick Next to continue."
LangString TEXT_WELCOME_PRODUCT_TEXT ${LANG_ENGLISH} "* MIDI Music Player$\n$\r* Time Chaser (MP3)$\n$\r* Counter-clock Clock\
$\n$\r* Berliner (Publication)$\n$\r* Magicus Oculus (PDF)$\n$\r* Stereograms"
; Password
LangString TEXT_PASS_TITLE ${LANG_ENGLISH} "Take a moment ..."
LangString TEXT_PASS_SUBTITLE ${LANG_ENGLISH} "Enter the password you were provided with."
LangString TEXT_PASS_BODY ${LANG_ENGLISH} "Please enter your password below and click Next, when you are ready."
LangString TEXT_PASS_CAPTION ${LANG_ENGLISH} "Your password:"
LangString MESSAGE_PASS_NOT ${LANG_ENGLISH} "The password field cannot be empty.    $\r$\n$\r$\n"
LangString MESSAGE_PASS_INCORRECT ${LANG_ENGLISH} "The password is incorrect.    $\r$\n$\r$\n"
; Uninstall
LangString TEXT_PREP_TITLE ${LANG_ENGLISH} "Already Installed"
LangString TEXT_PREP_SUBTITLE ${LANG_ENGLISH} "Choose how you want to install."
LangString TEXT_PREP_INFO ${LANG_ENGLISH} "$(^Name) is already installed. $7\
$\r$\n$\r$\nIt's recommended that you uninstall the copy before installing. Select the operation you want to \
perform and click Next to continue."
LangString TEXT_PREP_PREV ${LANG_ENGLISH} "&Uninstall first"
LangString TEXT_PREP_NOT ${LANG_ENGLISH} "&Do not uninstall"
LangString TEXT_PREP_NOTE ${LANG_ENGLISH} "To uninstall other versions, if present, you can also use \
the uninstaller in the bin folder of the version of $(^Name) you wish to remove."
; Ready
LangString TEXT_READY_TITLE ${LANG_ENGLISH} "Ready to Install"
LangString TEXT_READY_SUBTITLE ${LANG_ENGLISH} "Setup is now ready to start installing $(^Name)."
LangString TEXT_READY_BODY ${LANG_ENGLISH} "Click Install to continue with the \
installation, or Back if you want to review or make changes to the settings."
LangString TEXT_READY_GROUPHEAD ${LANG_ENGLISH} "Install Settings"
LangString TEXT_READY_TASKLIST_A ${LANG_ENGLISH} "Destination Folder:"
LangString TEXT_READY_TASKLIST_B ${LANG_ENGLISH} "Start Menu Folder:"
LangString TEXT_READY_DESKTOP ${LANG_ENGLISH} "&Install desktop icon"
; Finish
LangString M_TEXT_FINISH_INFO_TEXT ${LANG_ENGLISH} "$(^NameDA) has been installed. You can \
click Finish to complete and close Setup."
LangString M_TEXT_FINISH_RUN ${LANG_ENGLISH} "&Start $(^NameDA)"
LangString M_TEXT_FINISH_SHOWREADME ${LANG_ENGLISH} "&View Help"
LangString M_BUTTONTEXT_FINISH ${LANG_ENGLISH} "&Finish"
; Shortcut
LangString SHORTCUT_REMOVE ${LANG_ENGLISH} "$SMPROGRAMS\$ICONS_GROUP\X TIG (uninstall).lnk"
LangString SHORTCUT_README ${LANG_ENGLISH} "$INSTDIR\shortcut\Read Me.lnk"
LangString SHORTCUT_OBOOK ${LANG_ENGLISH} "PDF - 2018 oBook oDition"
LangString SHORTCUT_BERLINER_SM ${LANG_ENGLISH} "$SMPROGRAMS\$ICONS_GROUP\Berliner.lnk"
LangString SHORTCUT_BERLINER ${LANG_ENGLISH} "HTML Executable Publication"
LangString SHORTCUT_HTA ${LANG_ENGLISH} "Browser Object"
LangString SHORTCUT_WELCOME ${LANG_ENGLISH} "$INSTDIR\shortcut\Welcome.lnk"
LangString SHORTCUT_WELCOME_PAGE ${LANG_ENGLISH} "Splash Page"
LangString SHORTCUT_START_PAGE ${LANG_ENGLISH} "TIG Menu"
LangString SHORTCUT_HELP_CONTEXT ${LANG_ENGLISH} "View Help"
; Message
#LangString MESSAGE_INST_LANG_TITLE ${LANG_ENGLISH} "Installer Language"
#LangString MESSAGE_INST_LANG_INFO ${LANG_ENGLISH} "Please select the language of the installer."
!ifdef MUI_UN_BANNER
LangString MESSAGE_BANNER_WAIT ${LANG_ENGLISH} "Uninstalling files. Please wait..."
LangString MESSAGE_BANNER_REMOVE_DONE ${LANG_ENGLISH} "Done."
LangString MESSAGE_BANNER_REMOVE_FAIL ${LANG_ENGLISH} "One or more folders/files could not be removed from \
$PATH. Please check the path.    $\r$\n$\r$\n\
Click Cancel to stop the installation, or OK to continue.    $\r$\n$\r$\n"
!endif
LangString MESSAGE_DIR_USED ${LANG_ENGLISH} "The selected folder is not empty. Please    $\r$\n\
choose another destination.    $\r$\n$\r$\n"
LangString MESSAGE_SMF_USED ${LANG_ENGLISH} "The selected folder is not empty. Please choose    $\r$\n\
another Start Menu location.    $\r$\n$\r$\n"
LangString MESSAGE_ABORT ${LANG_ENGLISH} "Better luck next time.    $\r$\n$\r$\n"
LangString MESSAGE_ABORT_ACCESS ${LANG_ENGLISH} "The setup cannot continue because access is denied. Please    $\r$\n\
see your system administrator to install $(^Name).    $\r$\n$\r$\n"
; DetailPrint
LangString DETAIL_NOT_FOUND  ${LANG_ENGLISH} "Could not find file: "
LangString DETAIL_DATA ${LANG_ENGLISH} "Compressing Uninstall Data..."

;--------------------------------
; German

LangString M_TEXT_WELCOME_INFO_TITLE ${LANG_GERMAN} "Willkommen$\n$\rbeim Setup$\n$\rfür $(^NameDA)"
LangString M_TEXT_WELCOME_INFO_TEXT ${LANG_GERMAN} "Dieser Assistent wird Sie durch die Installation von \
$(^NameDA) führen. Klicken$\n$\rSie auf Weiter, um fortzufahren."
LangString TEXT_WELCOME_PRODUCT_TEXT ${LANG_GERMAN} "* MIDI Music Player$\n$\r* Time Chaser (MP3)$\n$\r* Counter-clock Clock\
$\n$\r* Berliner (Publikation)$\n$\r* Magicus Oculus (PDF)$\n$\r* Stereogramme"
; Password
LangString TEXT_PASS_TITLE ${LANG_GERMAN} "Einen Augenblick noch ..."
LangString TEXT_PASS_SUBTITLE ${LANG_GERMAN} "Geben Sie das Ihnen mitgeteilte Passwort ein."
LangString TEXT_PASS_BODY ${LANG_GERMAN} "Bitte geben Sie Ihr Passwort unten ein, und klicken Sie auf Weiter, wenn Sie \
bereit sind."
LangString TEXT_PASS_CAPTION ${LANG_GERMAN} "Ihr Passwort:"
LangString MESSAGE_PASS_NOT ${LANG_GERMAN} "Das Passwort Feld kann nicht leer sein.    $\r$\n$\r$\n"
LangString MESSAGE_PASS_INCORRECT ${LANG_GERMAN} "Das Passwort ist falsch.    $\r$\n$\r$\n"
; Uninstall
LangString TEXT_PREP_TITLE ${LANG_GERMAN} "Bereits Installiert"
LangString TEXT_PREP_SUBTITLE ${LANG_GERMAN} "Wählen Sie, wie Sie installieren möchten."
LangString TEXT_PREP_INFO ${LANG_GERMAN} "$(^Name) ist bereits installiert. $7\
$\r$\n$\r$\nEs wird empfohlen die Kopie zu deinstallieren. Wählen Sie die auszuführende Aktion aus und \
klicken Sie auf Weiter, um fortzufahren."
LangString TEXT_PREP_PREV ${LANG_GERMAN} "&Vor der Installation deinstallieren"
LangString TEXT_PREP_NOT ${LANG_GERMAN} "&Nicht deinstallieren"
LangString TEXT_PREP_NOTE ${LANG_GERMAN} "Weitere Versionen von $(^Name), falls vorhanden, können Sie auch durch die \
Uninstall-Anwendung deinstallieren, die sich im Ordner bin der Version, die Sie entfernen wollen, befindet."
; Ready
LangString TEXT_READY_TITLE ${LANG_GERMAN} "Installation durchführen"
LangString TEXT_READY_SUBTITLE ${LANG_GERMAN} "Das Setup ist jetzt bereit $(^Name) zu installieren."
LangString TEXT_READY_BODY ${LANG_GERMAN} "Klicken Sie auf Installieren, um mit der \
Installation zu beginnen, oder auf Züruck, um Ihre Einstellungen zu überprüfen \
oder zu ändern."
LangString TEXT_READY_GROUPHEAD ${LANG_GERMAN} "Setup Einstellungen"
LangString TEXT_READY_TASKLIST_A ${LANG_GERMAN} "Zielverzeichnis:"
LangString TEXT_READY_TASKLIST_B ${LANG_GERMAN} "Startmenü-Ordner:"
LangString TEXT_READY_DESKTOP ${LANG_GERMAN} "&Desktop-Symbol anlegen"
; Finish
LangString M_TEXT_FINISH_INFO_TEXT ${LANG_GERMAN} "$(^NameDA) wurde installiert. Klicken \
Sie auf Fertig, um das Setup abzuschließen."
LangString M_TEXT_FINISH_RUN ${LANG_GERMAN} "&$(^NameDA) starten"
LangString M_TEXT_FINISH_SHOWREADME ${LANG_GERMAN} "&Help öffnen"
LangString M_BUTTONTEXT_FINISH ${LANG_GERMAN} "&Fertig"
; Shortcut
LangString SHORTCUT_REMOVE ${LANG_GERMAN} "$SMPROGRAMS\$ICONS_GROUP\X TIG (deinstallieren).lnk"
LangString SHORTCUT_README ${LANG_GERMAN} "$INSTDIR\shortcut\Lies Mich.lnk"
LangString SHORTCUT_OBOOK ${LANG_GERMAN} "PDF - 2018 oBook oDition"
LangString SHORTCUT_BERLINER_SM ${LANG_GERMAN} "$SMPROGRAMS\$ICONS_GROUP\Berliner.lnk"
LangString SHORTCUT_BERLINER ${LANG_GERMAN} "HTML Executable Publikation"
LangString SHORTCUT_HTA ${LANG_GERMAN} "Browser Objekt"
LangString SHORTCUT_WELCOME ${LANG_GERMAN} "$INSTDIR\shortcut\Willkommen.lnk"
LangString SHORTCUT_WELCOME_PAGE ${LANG_GERMAN} "Splash Seite"
LangString SHORTCUT_START_PAGE ${LANG_GERMAN} "TIG Menü"
LangString SHORTCUT_HELP_CONTEXT ${LANG_GERMAN} "Help öffnen"
; Message
#LangString MESSAGE_INST_LANG_TITLE ${LANG_GERMAN} "Installations Sprache"
#LangString MESSAGE_INST_LANG_INFO ${LANG_GERMAN} "Bitte wählen Sie eine Sprache."
!ifdef MUI_UN_BANNER
LangString MESSAGE_BANNER_WAIT ${LANG_GERMAN} "Lösche Dateien. Bitte warten..."
LangString MESSAGE_BANNER_REMOVE_DONE ${LANG_GERMAN} "Fertig."
LangString MESSAGE_BANNER_REMOVE_FAIL ${LANG_GERMAN} "Eine oder mehrere Ordner/Dateien in dem Verzeichnis \
$PATH konnten nicht gelöscht werden. Bitte sehen Sie nach.    $\r$\n$\r$\n\
Klicken Sie auf Abbrechen, um die Installation zu beenden, oder auf OK, um fortzufahren.    $\r$\n$\r$\n"
!endif
LangString MESSAGE_DIR_USED ${LANG_GERMAN} "Das angegebene Zielverzeichnis ist nicht leer. Bitte    $\r$\n\
wählen Sie einen anderen Ordner.    $\r$\n$\r$\n"
LangString MESSAGE_SMF_USED ${LANG_GERMAN} "Das gewählte Verzeichnis ist nicht leer. Bitte suchen    $\r$\n\
Sie einen anderen Startmenü-Ordner aus.    $\r$\n$\r$\n"
LangString MESSAGE_ABORT ${LANG_GERMAN} "Beim nächsten Mal haben Sie mehr Glück!    $\r$\n$\r$\n"
LangString MESSAGE_ABORT_ACCESS ${LANG_GERMAN} "Setup kann nicht fortgesetzt werden, weil ein Zugriff \
verweigert ist.    $\r$\n\Bitte wenden Sie sich an Ihren System-Administrator.    $\r$\n$\r$\n"
; DetailPrint
LangString DETAIL_NOT_FOUND  ${LANG_GERMAN} "Datei ist nicht vorhanden: "
LangString DETAIL_DATA ${LANG_GERMAN} "Kompremiere Deinstallations-Daten..."

################################## unLanguageStringsFull.nsh ##################################

; Tom’s Image Gallery 2.1 Setup Uninstall (full) Language Strings include (TN)
;--------------------------------

!ifndef MUI_MODIFIED
; MUI 2 changes - English
LangString M_UNTEXT_CONFIRM_TITLE ${LANG_ENGLISH} "Uninstall"
; MUI 2 changes - German
LangString M_UNTEXT_CONFIRM_TITLE ${LANG_GERMAN} "Deinstallation"
!endif

;--------------------------------
; English

LangString M_UNTEXT_WELCOME_INFO_TITLE ${LANG_ENGLISH} "Welcome$\n$\rto the $(^NameDA)$\n$\rUninstall"
LangString M_UNTEXT_WELCOME_INFO_TEXT ${LANG_ENGLISH} "Setup will guide you through the uninstallation of \
$(^NameDA). Please click$\n$\rNext to continue."
LangString M_UNTEXT_FINISH_INFO_TEXT ${LANG_ENGLISH} "$(^NameDA) has been uninstalled from your computer. \
You can click Finish$\n$\rto close Setup."
LangString MESSAGE_UNABORT ${LANG_ENGLISH} "$(^Name) uninstall did not complete successfully.    $\r$\n$\r$\n"
LangString MESSAGE_UNABORT_N ${LANG_ENGLISH} "The operating system denied access. You do not have    $\r$\n\
permission to uninstall $(^Name). Please restart the    $\r$\n\
uninstaller with Administrator privileges.    $\r$\n$\r$\n"
LangString MESSAGE_UNABORT_UAC ${LANG_ENGLISH} "The uninstallation should be run with Administrative privileges.    $\r$\n$\r$\n"
LangString MESSAGE_UNABORT_PROFILE ${LANG_ENGLISH} "The uninstallation cannot continue because    $\r$\n\
access is denied.    $\r$\n$\r$\n"
#LangString MESSAGE_REMOVE ${LANG_ENGLISH} "Are you sure you want to completely remove $(^Name)?    $\r$\n$\r$\n"
#LangString MESSAGE_REMOVE_SUCCESS ${LANG_ENGLISH} "$(^Name) has been uninstalled from your computer.    $\r$\n$\r$\n"
LangString TEXT_WELCOME_TITLE ${LANG_ENGLISH} "Hello,"
LangString TEXT_WELCOME_SUBTITLE ${LANG_ENGLISH} "And welcome to the $(^Name) Uninstall Wizard."
; DetailPrint
LangString DETAIL_ERRORS ${LANG_ENGLISH} "Locked files:"
LangString DETAIL_REMOVED_S ${LANG_ENGLISH} "$R3 files not deleted."
LangString DETAIL_REMOVED ${LANG_ENGLISH} "$R3 file not deleted."

;--------------------------------
; German

LangString M_UNTEXT_WELCOME_INFO_TITLE ${LANG_GERMAN} "Willkommen$\n$\rbeim$\n$\rDeinstallations-$\n$\rAssistenten\
$\n$\rfür $(^NameDA)"
LangString M_UNTEXT_WELCOME_INFO_TEXT ${LANG_GERMAN} "Dieser Assistent wird Sie durch die Deinstallation von \
$(^NameDA) führen.$\n$\rKlicken Sie auf Weiter, um fortzufahren."
LangString M_UNTEXT_FINISH_INFO_TEXT ${LANG_GERMAN} "$(^NameDA) ist von Ihrem Computer erfolgreich entfernt \
worden. Klicken$\n$\rSie auf Fertig, um den Assistenten zu schließen."
LangString MESSAGE_UNABORT ${LANG_GERMAN} "Die Deinstallation von $(^Name) wurde nicht erfolgreich abgeschlossen.    $\r$\n$\r$\n"
LangString MESSAGE_UNABORT_N ${LANG_GERMAN} "Das Betriebssystem verweigert den Zugriff. Sie haben keine    $\r$\n\
Berechtigung $(^Name) zu entfernen. Bitte starten Sie die    $\r$\n\
Deinstallation mit Administratorrechten.    $\r$\n$\r$\n"
LangString MESSAGE_UNABORT_UAC ${LANG_GERMAN} "Die Deinstallation sollte von einem Benutzer mit ausreichenden    $\r$\n\
Rechten, wie z.B. dem Systemadministrator, ausgeführt werden.    $\r$\n$\r$\n"
LangString MESSAGE_UNABORT_PROFILE ${LANG_GERMAN}  "Die Deinstallation kann nicht fortgesetzt werden,    $\r$\n\
weil ein Zugriff verweigert ist.    $\r$\n$\r$\n"
#LangString MESSAGE_REMOVE ${LANG_GERMAN} "Sind Sie sicher, dass Sie $(^Name) komplett entfernen wollen?    $\r$\n$\r$\n"
#LangString MESSAGE_REMOVE_SUCCESS ${LANG_GERMAN} "$(^Name) wurde von Ihrem Computer deinstalliert.    $\r$\n$\r$\n"
LangString TEXT_WELCOME_TITLE ${LANG_GERMAN} "Hallo."
LangString TEXT_WELCOME_SUBTITLE ${LANG_GERMAN} "Und willkommen beim Uninstall-Wizard für $(^Name)."
; DetailPrint
LangString DETAIL_ERRORS ${LANG_GERMAN} "Gesperrte Dateien:"
LangString DETAIL_REMOVED_S ${LANG_GERMAN} "$R3 Dateien nicht gelöscht."
LangString DETAIL_REMOVED ${LANG_GERMAN} "$R3 Datei nicht gelöscht."

###################################### setsize.nsi ######################################

; Tom’s Image Gallery 2.1 Size Script (TN)
; Compile this script and run "setsize.exe" before compiling "TIGsetup.exe"

Name "Set Size"
RequestExecutionLevel user
Unicode false ; use 'true' for unicode
!define LOCAL "..\" ; Path where local include files reside
!ifdef NSIS_UNICODE
  !define LOCAL_UA "..\unicode\" ; Path where unicode local include files are
!endif
!ifndef LOCAL_UA
  !define LOCAL_UA "..\ansi\" ; Path where ansi local include files are
!endif
OutFile "${LOCAL_UA}setsize.exe"
Icon "${LOCAL}arrows.ico"
!include "LogicLib.nsh"
!include "${LOCAL_UA}TIGmacros.nsh"
ReserveFile /plugin "Math.dll"
ShowInstDetails show

; Variables
Var BLOCK
Var S_X_A
Var S_X_W
Var S_A
Var S_W
Var S_Q
Var S
Var S_I
Var S_NI
Var S_NID
Var S_7
Var S_N7
Var S_TIG
Var S_TIGW
Var S_V
Var S_NV
Var S_SC98
Var S_SCXP
Var S_SCV
Var S_SC8
Var S_SC10
Var S_SCF
Var S_JNLP
Var SOD_X_A
Var SOD_X_W
Var SOD_A
Var SOD_W
Var SOD_Q
Var SOD
Var SOD_I
Var SOD_NI
Var SOD_NID
Var SOD_7
Var SOD_N7
Var SOD_TIG
Var SOD_TIGW
Var SOD_V
Var SOD_NV
Var SOD_SCF
Var SOD_JNLP
Var F
Var D
Var T_0
Var A_0
Var T_1
Var A_1
Var desktopini
Var thumbsdb
Var everything

;--------------------------------
; Size

Function SectionSize

  ; physical size in bytes
  StrCpy $S_X_A 16 # ; flash trust certificate (approximate) - file written to system folder
  StrCpy $S_X_W 34 # ; unicode flash trust certificate (approximate) - file written to system folder
  StrCpy $S_A 0 # ; no uninstaller
  StrCpy $S_W 0 # ; no unicode uninstaller
  IfFileExists "F:\homepage\nsis\bin\uninst.exe" 0 fA ; temporary uninstaller file
    ${GetSizeOnDisk} "F:\homepage\nsis\bin" "/M=uninst.exe /S=0B /G=0" "" $0 $1 $2 $3
    StrCpy $S_A $0 #
  fA:
  IfFileExists "F:\homepage\nsis\bin\uuninst.exe" 0 fW ; temporary unicode uninstaller file
    ${GetSizeOnDisk} "F:\homepage\nsis\bin" "/M=uuninst.exe /S=0B /G=0" "" $0 $1 $2 $3
    StrCpy $S_W $0 #
  fW:
  ; Shortcut .lnk files are smaller
  IntOp $S_SC98 5647 * -1 ; Windows 98
  IntOp $S_SCXP 1109 * -1 ; Windows XP
  IntOp $S_SCV 695 * -1 ; Windows Vista
  ; Shortcut .lnk files are larger
  StrCpy $S_SC8 72 # ; windows 8+
  StrCpy $S_SC10 180 # ; windows 10+
  ; Quick compile (1 file)
  ${GetSizeOnDisk} "F:\Gallery" "/M=index.hta /S=0B /G=0" "" $0 $1 $2 $3
  StrCpy $S_Q $0 #
  ; All source files
  ${GetSizeOnDisk} "F:\Gallery" "/S=0B" "" $0 $1 $2 $3
  StrCpy $S $0 #
  StrCpy $F $1 #
  StrCpy $everything $1
  StrCpy $D $2 #
  IntOp $F $F + 1 ; uninstaller file
  IntOp $D $D + 1 ; bin folder
  ; subtract files and folders
  ${GetSizeOnDisk} "F:\Gallery" "/M=*.php /S=0B" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; php files (not installed)
  IntOp $F $F - $1
  ${GetSizeOnDisk} "F:\Gallery" "/M=desktop.ini /S=0B" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; desktop.ini files (not installed)
  StrCpy $desktopini $1 #
  IntOp $F $F - $1
  ${GetSizeOnDisk} "F:\Gallery" "/M=thumbs.db /S=0B" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; thumbs.db files (not installed)
  StrCpy $thumbsdb $1 #
  IntOp $F $F - $1
  ${GetSizeOnDisk} "F:\Gallery" "/M=TIG.exe.manifest /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; wxWidgets TIG menu manifest (not installed)
  IntOp $F $F - $1
  ${GetSizeOnDisk} "F:\Gallery" "/M=ft*.htm /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; htm (not installed)
  IntOp $F $F - $1
  ${GetSizeOnDisk} "F:\Gallery" "/M=fmo*.htm /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; htm (not installed)
  IntOp $F $F - $1
  ${GetSizeOnDisk} "F:\Gallery" "/M=ht*.htm /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; htm (not installed)
  IntOp $F $F - $1
  ${GetSizeOnDisk} "F:\Gallery" "/M=pid*.htm /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; htm (not installed)
  IntOp $F $F - $1
  ${GetSizeOnDisk} "F:\Gallery" "/M=tigp2.htm /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; htm file (not installed)
  IntOp $F $F - 1
  ${GetSizeOnDisk} "F:\Gallery" "/M=tigp3.htm /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; htm file (not installed)
  IntOp $F $F - 1
  ${GetSizeOnDisk} "F:\Gallery" "/M=tigp4.htm /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; htm file (not installed)
  IntOp $F $F - 1
  ${GetSizeOnDisk} "F:\Gallery" "/M=tigp5.htm /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; htm file (not installed)
  IntOp $F $F - 1
  ${GetSizeOnDisk} "F:\Gallery" "/M=tigp6.htm /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; htm file (not installed)
  IntOp $F $F - 1
  ${GetSizeOnDisk} "F:\Gallery" "/M=tigp7.htm /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; htm file (not installed)
  IntOp $F $F - 1
  ${GetSizeOnDisk} "F:\Gallery" "/M=tigp8.htm /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; htm file (not installed)
  IntOp $F $F - 1
  ${GetSizeOnDisk} "F:\Gallery" "/M=berlinervsfx.exe /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; sfx (not installed)
  IntOp $F $F - 1
  ${GetSizeOnDisk} "F:\Gallery\aforest" "/M=*shot.png /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; png (not installed)
  IntOp $F $F - $1
  ${GetSizeOnDisk} "F:\Gallery\aforest" "/M=*.js /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; js (not installed)
  IntOp $F $F - $1
  ${GetSizeOnDisk} "F:\Gallery\aforest" "/M=*.jpg /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; jpg (not installed)
  IntOp $F $F - $1
  ${GetSizeOnDisk} "F:\Gallery\aforest" "/M=*.htm /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; htm (not installed)
  IntOp $F $F - $1
  ${GetSizeOnDisk} "F:\Gallery\aforest" "/M=*.gif /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; gif (not installed)
  IntOp $F $F - $1
  ${GetSizeOnDisk} "F:\Gallery\aforest" "/M=*.css /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; css (not installed)
  IntOp $F $F - $1
  ${GetSizeOnDisk} "F:\Gallery\graphics" "/M=complogo.gif /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; gif file (not installed)
  IntOp $F $F - 1
  ${GetSizeOnDisk} "F:\Gallery\thumbs" "/M=22trisk.jpg /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; jpg file (not installed)
  IntOp $F $F - 1
  ${GetSizeOnDisk} "F:\Gallery\thumbs" "/M=theend3d.jpg /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S - $0 ; jpg file (not installed)
  IntOp $F $F - 1
  ; add files
  ${GetSizeOnDisk} "F:\Gallery\aforest" "/M=size.js /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S + $0 ; js file (is installed)
  IntOp $F $F + $1
  ; install path == C:\Gallery
  ${GetSizeOnDisk} "F:\Gallery\acrohome" "/S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S_I $0 * -1
  ${GetSizeOnDisk} "F:\Gallery\js" "/M=ice.js /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S_I $S_I - $0
  ${GetSizeOnDisk} "F:\Gallery\menu" "/M=index.html /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S_I $S_I - $0
  ; install path != C:\Gallery
  ${GetSizeOnDisk} "F:\Gallery\acroice" "/S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S_NI $0 * -1
  IntOp $F $F - $1
  IntOp $D $D - 1
  ${GetSizeOnDisk} "F:\Gallery\jsice" "/M=ice.js /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S_NI $S_NI - $0
  IntOp $F $F - 1
  IntOp $D $D - 1
  ${GetSizeOnDisk} "F:\Gallery\menu" "/M=indexi.html /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S_NI $S_NI - $0
  IntOp $F $F - 1
  ; difference
  IntOp $S_NID $S_I - $S_NI
  ; add rtf license
  ${GetSizeOnDisk} "F:\homepage\nsis" "/M=license.rtf /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S $S + $0
  IntOp $F $F + 1
  ; htmlexe 4.x version (at least WinVista SP2)
  ${GetSizeOnDisk} "F:\Gallery" "/M=berliner.exe /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S_7 $0 * -1
  ; htmlexe 3.5 version (pre-WinVista SP2)
  ${GetSizeOnDisk} "F:\Gallery" "/M=berlinerv.exe /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S_N7 $0 * -1
  IntOp $F $F - 1
  ; subtract ansi menu (TIGW.exe)
  ${GetSizeOnDisk} "F:\Gallery" "/M=TIG.exe /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S_TIGW $0 * -1
  ; subtract unicode menu (TIG.exe) XP or higher
  ${GetSizeOnDisk} "F:\Gallery" "/M=TIGW.exe /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S_TIG $0 * -1
  IntOp $F $F - 1
  ; subtract xp icons (at least WinVista)
  ${GetSizeOnDisk} "F:\Gallery\icons" "/M=tchaser.ico /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S_V $0 * -1
  ${GetSizeOnDisk} "F:\Gallery\icons" "/M=mmp.ico /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S_V $S_V - $0
  ${GetSizeOnDisk} "F:\Gallery\icons" "/M=oBook.ico /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S_V $S_V - $0
  ${GetSizeOnDisk} "F:\Gallery\icons" "/M=gallery.ico /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S_V $S_V - $0
  ; subtract aero icons (pre-WinVista)
  ${GetSizeOnDisk} "F:\Gallery\icons" "/M=*v.ico /S=0B /G=0" "" $0 $1 $2 $3
  IntOp $S_NV $0 * -1
  IntOp $F $F - 4
  ; runtime variables
  ${GetSizeOnDisk} "F:\Gallery\shortcut" "/M=*.lnk /S=0B /G=0" "" $0 $1 $2 $3
  StrCpy $S_SCF $0 # ; shortcuts
  ${GetSizeOnDisk} "F:\Gallery" "/M=jtssjar.jnlp /S=0B /G=0" "" $0 $1 $2 $3
  StrCpy $S_JNLP $0 # ; java file

  ; size on disk (logical size) - in kilobytes
  StrCpy $BLOCK 4096 #
  Math::Script "b = $BLOCK; \
  a = $S_X_A; c = a % b; #[c == 0, c = $BLOCK]; \
  R1 = (b - c + a) / 1024; \
  a = $S_X_W; c = a % b; #[c == 0, c = $BLOCK]; \
  R2 = (b - c + a) / 1024; \
  a = $S_A; c = a % b; #[c == 0, c = $BLOCK]; \
  R3 = (b - c + a) / 1024; \
  a = $S_W; c = a % b; #[c == 0, c = $BLOCK]; \
  R4 = (b - c + a) / 1024"
  StrCpy $SOD_X_A $R1 # ; ansi certificate
  StrCpy $SOD_X_W $R2 # ; unicode certificate
  StrCpy $SOD_A $R3 # ; ansi uninstaller
  StrCpy $SOD_W $R4 # ; unicode uninstaller
  ; Quick compile (1 file)
  ${GetSizeOnDisk} "F:\Gallery" "/M=index.hta /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  StrCpy $SOD_Q $0 #
  ; All source files
  ${GetSizeOnDisk} "F:\Gallery" "/S=0K" "$BLOCK" $0 $1 $2 $3
  StrCpy $SOD $0 #
  ; subtract files
  ${GetSizeOnDisk} "F:\Gallery" "/M=*.php /S=0K" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; php files (not installed)
  ${GetSizeOnDisk} "F:\Gallery" "/M=desktop.ini /S=0K" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; desktop.ini files (not installed)
  ${GetSizeOnDisk} "F:\Gallery" "/M=thumbs.db /S=0K" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; thumbs.db files (not installed)
  ${GetSizeOnDisk} "F:\Gallery" "/M=TIG.exe.manifest /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; wxWidgets TIG menu manifest (not installed)
  ${GetSizeOnDisk} "F:\Gallery" "/M=ft*.htm /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; htm (not installed)
  ${GetSizeOnDisk} "F:\Gallery" "/M=fmo*.htm /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; htm (not installed)
  ${GetSizeOnDisk} "F:\Gallery" "/M=hta*.htm /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; htm (not installed)
  ${GetSizeOnDisk} "F:\Gallery" "/M=pid*.htm /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; htm (not installed)
  ${GetSizeOnDisk} "F:\Gallery" "/M=tigp2.htm /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; htm file (not installed)
  ${GetSizeOnDisk} "F:\Gallery" "/M=tigp3.htm /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; htm file (not installed)
  ${GetSizeOnDisk} "F:\Gallery" "/M=tigp4.htm /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; htm file (not installed)
  ${GetSizeOnDisk} "F:\Gallery" "/M=tigp5.htm /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; htm file (not installed)
  ${GetSizeOnDisk} "F:\Gallery" "/M=tigp6.htm /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; htm file (not installed)
  ${GetSizeOnDisk} "F:\Gallery" "/M=tigp7.htm /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; htm file (not installed)
  ${GetSizeOnDisk} "F:\Gallery" "/M=tigp8.htm /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; htm file (not installed)
  ${GetSizeOnDisk} "F:\Gallery" "/M=berlinervsfx.exe /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; sfx (not installed)
  ${GetSizeOnDisk} "F:\Gallery\aforest" "/M=*shot.png /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; png (not installed)
  ${GetSizeOnDisk} "F:\Gallery\aforest" "/M=*.js /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; js (not installed)
  ${GetSizeOnDisk} "F:\Gallery\aforest" "/M=*.jpg /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; jpg (not installed)
  ${GetSizeOnDisk} "F:\Gallery\aforest" "/M=*.htm /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; htm (not installed)
  ${GetSizeOnDisk} "F:\Gallery\aforest" "/M=*.gif /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; gif (not installed)
  ${GetSizeOnDisk} "F:\Gallery\aforest" "/M=*.css /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; css (not installed)
  ${GetSizeOnDisk} "F:\Gallery\graphics" "/M=complogo.gif /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; gif file (not installed)
  ${GetSizeOnDisk} "F:\Gallery\thumbs" "/M=22trisk.jpg /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; jpg file (not installed)
  ${GetSizeOnDisk} "F:\Gallery\thumbs" "/M=theend3d.jpg /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD - $0 ; jpg file (not installed)
  ; add files
  ${GetSizeOnDisk} "F:\Gallery\aforest" "/M=size.js /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD + $0 ; js file (is installed)
  ; install path == C:\Gallery
  ${GetSizeOnDisk} "F:\Gallery\acrohome" "/S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD_I $0 * -1
  ${GetSizeOnDisk} "F:\Gallery\js" "/M=ice.js /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD_I $SOD_I - $0
  ${GetSizeOnDisk} "F:\Gallery\menu" "/M=index.html /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD_I $SOD_I - $0
  ; install path != C:\Gallery
  ${GetSizeOnDisk} "F:\Gallery\acroice" "/S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD_NI $0 * -1
  ${GetSizeOnDisk} "F:\Gallery\jsice" "/M=ice.js /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD_NI $SOD_NI - $0
  ${GetSizeOnDisk} "F:\Gallery\menu" "/M=indexi.html /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD_NI $SOD_NI - $0
  ; difference
  IntOp $SOD_NID $SOD_I - $SOD_NI
  ; add rtf license
  ${GetSizeOnDisk} "F:\homepage\nsis" "/M=license.rtf /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD $SOD + $0
  ; htmlexe 4.x version (at least WinVista SP2)
  ${GetSizeOnDisk} "F:\Gallery" "/M=berliner.exe /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD_7 $0 * -1
  ; htmlexe 3.5 version (pre-WinVista SP2)
  ${GetSizeOnDisk} "F:\Gallery" "/M=berlinerv.exe /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD_N7 $0 * -1
  ; TIGW.exe - subtract ansi menu (XP+)
  ${GetSizeOnDisk} "F:\Gallery" "/M=TIG.exe /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD_TIGW $0 * -1
  ; TIG.exe - subtract unicode menu
  ${GetSizeOnDisk} "F:\Gallery" "/M=TIGW.exe /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD_TIG $0 * -1
  ; subtract xp icons (at least WinVista)
  ${GetSizeOnDisk} "F:\Gallery\icons" "/M=tchaser.ico /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD_V $0 * -1
  ${GetSizeOnDisk} "F:\Gallery\icons" "/M=mmp.ico /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD_V $SOD_V - $0
  ${GetSizeOnDisk} "F:\Gallery\icons" "/M=oBook.ico /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD_V $SOD_V - $0
  ${GetSizeOnDisk} "F:\Gallery\icons" "/M=gallery.ico /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD_V $SOD_V - $0
  ; subtract aero icons (pre-WinVista)
  ${GetSizeOnDisk} "F:\Gallery\icons" "/M=*v.ico /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  IntOp $SOD_NV $0 * -1
  ; runtime variables
  ${GetSizeOnDisk} "F:\Gallery\shortcut" "/M=*.lnk /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  StrCpy $SOD_SCF $0 # ; shortcuts
  ${GetSizeOnDisk} "F:\Gallery" "/M=jtssjar.jnlp /S=0K /G=0" "$BLOCK" $0 $1 $2 $3
  StrCpy $SOD_JNLP $0 # ; java file

  ; count the number of "text*.htm" files
  FindFirst $0 $1 F:\Gallery\text*.htm
  ${DoUntil} ${Errors}
  ${If} ${FileExists} F:\Gallery\$1
  IntOp $T_0 $T_0 + 1
  ${EndIf}
  FindNext $0 $1
  ${Loop}
  FindClose $0
  ; and the number of "add*.htm" files
  FindFirst $0 $1 F:\Gallery\add*.htm
  ${DoUntil} ${Errors}
  ${If} ${FileExists} F:\Gallery\$1
  IntOp $A_0 $A_0 + 1
  ${EndIf}
  FindNext $0 $1
  ${Loop}
  FindClose $0
  ; count the number of "mo_t*.htm" files
  FindFirst $0 $1 F:\Gallery\mo_t*.htm
  ${DoUntil} ${Errors}
  ${If} ${FileExists} F:\Gallery\$1
  IntOp $T_1 $T_1 + 1
  ${EndIf}
  FindNext $0 $1
  ${Loop}
  FindClose $0
  ; and the number of "mo_a*.htm" files
  FindFirst $0 $1 F:\Gallery\mo_a*.htm
  ${DoUntil} ${Errors}
  ${If} ${FileExists} F:\Gallery\$1
  IntOp $A_1 $A_1 + 1
  ${EndIf}
  FindNext $0 $1
  ${Loop}
  FindClose $0

FunctionEnd

!define SectionSize "Call SectionSize"

Section
  DetailPrint "S_X_A $S_X_A"
  DetailPrint "S_X_W $S_X_W"
  DetailPrint "S_A $S_A"
  DetailPrint "S_W $S_W"
  DetailPrint "S_Q $S_Q"
  DetailPrint "S_All $S"
  DetailPrint "S_I $S_I"
  DetailPrint "S_NI $S_NI"
  DetailPrint "S_NID $S_NID"
  DetailPrint "S_Win7 $S_7"
  DetailPrint "S_WinN7 $S_N7"
  DetailPrint "S_TIG $S_TIG"
  DetailPrint "S_TIGW $S_TIGW"
  DetailPrint "S_WinV $S_V"
  DetailPrint "S_WinNV $S_NV"
  DetailPrint "S_SC98 $S_SC98"
  DetailPrint "S_SCXP $S_SCXP"
  DetailPrint "S_SCV $S_SCV"
  DetailPrint "S_SC8 $S_SC8" ; potentially 0 bytes - logical size
  DetailPrint "S_SC10 $S_SC10" ; potentially 0 bytes - logical size
  DetailPrint "S_SCF $S_SCF"
  DetailPrint "S_JNLP $S_JNLP"
  DetailPrint "F_FILES $F"
  DetailPrint "D_FOLDERS $D"
  DetailPrint ""
  DetailPrint "SOD_X_A $SOD_X_A"
  DetailPrint "SOD_X_W $SOD_X_W"
  DetailPrint "SOD_A $SOD_A"
  DetailPrint "SOD_W $SOD_W"
  DetailPrint "SOD_Q $SOD_Q"
  DetailPrint "SOD_All $SOD"
  DetailPrint "SOD_I $SOD_I"
  DetailPrint "SOD_NI $SOD_NI"
  DetailPrint "SOD_NID $SOD_NID"
  DetailPrint "SOD_Win7 $SOD_7"
  DetailPrint "SOD_WinN7 $SOD_N7"
  DetailPrint "SOD_TIG $SOD_TIG"
  DetailPrint "SOD_TIGW $SOD_TIGW"
  DetailPrint "SOD_WinV $SOD_V"
  DetailPrint "SOD_WinNV $SOD_NV"
  DetailPrint "SOD_SCF $SOD_SCF"
  DetailPrint "SOD_JNLP $SOD_JNLP"
  DetailPrint "F_FILES $F"
  DetailPrint "D_FOLDERS $D"
  DetailPrint ""
  DetailPrint "T_0 $T_0"
  DetailPrint "A_0 $A_0"
  DetailPrint "T_1 $T_1"
  DetailPrint "A_1 $A_1"
  DetailPrint ""
  ## caution! - system hidden files might not be counted depending on OS quirks ##
  DetailPrint "desktop.ini $desktopini"
  DetailPrint "thumbs.db $thumbsdb"
  DetailPrint ""
  DetailPrint "total # of files $everything"
  ; write to file
  ; === String All ===
  StrCpy $R0 "!define S_X_A $S_X_A$\r$\n!define S_X_W $S_X_W$\r$\n!define S_A $S_A$\r$\n!define S_W $S_W$\r$\n!define S_Q $S_Q\
  $\r$\n!define S_All $S$\r$\n!define S_NI $S_NI$\r$\n!define S_NID $S_NID$\r$\n!define S_Win7 $S_7$\r$\n!define S_WinN7 $S_N7\
  $\r$\n!define S_TIG $S_TIG$\r$\n!define S_TIGW $S_TIGW$\r$\n!define S_WinV $S_V$\r$\n!define S_WinNV $S_NV$\r$\n!define S_SC98 $S_SC98\
  $\r$\n!define S_SCXP $S_SCXP$\r$\n!define S_SCV $S_SCV$\r$\n!define S_SC8 $S_SC8$\r$\n!define S_SC10 $S_SC10$\r$\n!define S_SCF $S_SCF\
  $\r$\n!define S_JNLP $S_JNLP$\r$\n!define F_FILES $F$\r$\n!define D_FOLDERS $D$\r$\n!define SOD_X_A $SOD_X_A$\r$\n!define SOD_X_W $SOD_X_W\
  $\r$\n!define SOD_A $SOD_A$\r$\n!define SOD_W $SOD_W$\r$\n!define SOD_Q $SOD_Q$\r$\n!define SOD_All $SOD$\r$\n!define SOD_NI $SOD_NI\
  $\r$\n!define SOD_NID $SOD_NID$\r$\n!define SOD_Win7 $SOD_7$\r$\n!define SOD_WinN7 $SOD_N7$\r$\n!define SOD_TIG $SOD_TIG\
  $\r$\n!define SOD_TIGW $SOD_TIGW$\r$\n!define SOD_WinV $SOD_V$\r$\n!define SOD_WinNV $SOD_NV$\r$\n!define SOD_SCF $SOD_SCF\
  $\r$\n!define SOD_JNLP $SOD_JNLP$\r$\n!define T_0 $T_0$\r$\n!define A_0 $A_0$\r$\n!define T_1 $T_1$\r$\n!define A_1 $A_1$\r$\n\
  $\r$\n## desktopini $desktopini$\r$\n## thumbsdb $thumbsdb$\r$\n" #
  ; === String S ===
  StrCpy $R1 "!define S_X_A $S_X_A$\r$\n!define S_X_W $S_X_W$\r$\n!define S_A $S_A$\r$\n!define S_W $S_W$\r$\n!define S_Q $S_Q\
  $\r$\n!define S_All $S$\r$\n!define S_NI $S_NI$\r$\n!define S_NID $S_NID$\r$\n!define S_Win7 $S_7$\r$\n!define S_WinN7 $S_N7\
  $\r$\n!define S_TIG $S_TIG$\r$\n!define S_TIGW $S_TIGW$\r$\n!define S_WinV $S_V$\r$\n!define S_WinNV $S_NV$\r$\n!define S_SC98 $S_SC98\
  $\r$\n!define S_SCXP $S_SCXP$\r$\n!define S_SCV $S_SCV$\r$\n!define S_SC8 $S_SC8$\r$\n!define S_SC10 $S_SC10$\r$\n!define S_SCF $S_SCF\
  $\r$\n!define S_JNLP $S_JNLP$\r$\n!define F_FILES $F$\r$\n!define D_FOLDERS $D$\r$\n!define T_0 $T_0$\r$\n!define A_0 $A_0\
  $\r$\n!define T_1 $T_1$\r$\n!define A_1 $A_1$\r$\n$\r$\n## desktopini $desktopini$\r$\n## thumbsdb $thumbsdb$\r$\n" #
  ; === String SOD ===
  StrCpy $R2 "!define SOD_X_A $SOD_X_A$\r$\n!define SOD_X_W $SOD_X_W$\r$\n!define SOD_A $SOD_A$\r$\n!define SOD_W $SOD_W$\r$\n!define SOD_Q $SOD_Q\
  $\r$\n!define SOD_All $SOD$\r$\n!define SOD_NI $SOD_NI$\r$\n!define SOD_NID $SOD_NID$\r$\n!define SOD_Win7 $SOD_7$\r$\n!define SOD_WinN7 $SOD_N7\
  $\r$\n!define SOD_TIG $SOD_TIG$\r$\n!define SOD_TIGW $SOD_TIGW$\r$\n!define SOD_WinV $SOD_V$\r$\n!define SOD_WinNV $SOD_NV\
  $\r$\n!define SOD_SCF $SOD_SCF$\r$\n!define SOD_JNLP $SOD_JNLP$\r$\n!define F_FILES $F$\r$\n!define D_FOLDERS $D\
  $\r$\n!define T_0 $T_0$\r$\n!define A_0 $A_0$\r$\n!define T_1 $T_1$\r$\n!define A_1 $A_1$\r$\n\
  $\r$\n## desktopini $desktopini$\r$\n## thumbsdb $thumbsdb$\r$\n" #
  ClearErrors
  !ifndef NSIS_UNICODE
    FileOpen $0 "F:\homepage\nsis\ansi\setsize.nsh" w
    IfErrors completed
    FileWrite $0 $R1
  !else
    FileOpen $0 "F:\homepage\nsis\unicode\setsize.nsh" w
    IfErrors completed
    FileWriteWord $0 "65279"
    FileWriteUTF16LE $0 $R1
  !endif
  FileClose $0
completed:
SectionEnd

;--------------------------------
; Let's go.

Function .onInit
  ; Required Space & Estimated Size
  ${SectionSize}
FunctionEnd

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