@echo off

set EXE=..\software\iview-setup.exe
set ZIP=..\software\iview-plugins.zip
set CONFIG=config\i_view64.ini
set STARTMENU="%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs"
set TARGET="%PROGRAMFILES%\IrfanView"

if NOT EXIST %EXE% (
  echo ERROR: %EXE% not found!
  pause
  exit /b
)

echo ####### %0 #######

echo installing IrfanView ...
start /wait %EXE% /silent /desktop=1 /thumbs=1 /folder=%TARGET% /group=1 /allusers=1

echo sleeping 5 seconds ...
ping 127.0.0.1 -n 5 > NUL 2>&1

echo removing IrfanView startmenu folder ...
rd /S /Q %STARTMENU%\"IrfanView" 2>nul

echo moving IrfanView desktop links to Startmenu ...
mkdir %STARTMENU%\IrfanView 2>nul
move /Y "%PUBLIC%\Desktop\IrfanView*.lnk" %STARTMENU%\IrfanView

rem refresh desktop (W10 style)
ie4uinit.exe -show

if EXIST %ZIP% (
  echo extracting and installing PDF plugin ...
  7z -o%TARGET%\Plugins -aoa x %ZIP% PDF.dll 1>nul

  echo copying config file to enable new PDF lib ...
  copy /Y %CONFIG% %TARGET%

)

echo ####### %0 #######

