@echo off

set T=%SystemDrive%\TEMP
set TOOLS=%SystemDrive%\tools
set SOFTWARE=..\software

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

rem ###################################
rem Windows Defender Exceptions ...
rem ###################################

for %%A in (
  %T%
  %TOOLS%
) do (
  echo disabling Windows defender for PATH [ %%A ] ...
  powershell -inputformat none -outputformat none -NonInteractive -Command Add-MpPreference -ExclusionPath %%A
)

rem ###################################
rem MAIN loop ( unzip archives ) ...
rem ###################################

for %%A in (

  cmail
  curl
  desktopinfo
  devmanview
  mas
  nsudo
  offlineregistryfinder
  rclone
  rdpwrap
  registryfinder
  regscanner
  restic
  serviwin
  setdefaultbrowser
  showkeyplus
  sumatrapdf
  tcpoptimize
  trid
  triddefs
  vim
  wget
  wgetdeps
  winscp
  wub
  uwt

) do (
  
  if NOT EXIST %SOFTWARE%\%%A.zip (
    echo WARNING: %SOFTWARE%\%%A.zip not found!
  ) else (
    echo unpacking %%A.zip ...
    %TOOLS%\7z e -y -aoa -o%T%\%%A %SOFTWARE%\%%A.zip 1>nul
  )

)

echo.
echo ###################################
echo move files to tools folder
echo ###################################
echo.

echo CMail - a Windows mailer
move /Y %T%\cmail\cmail.exe %TOOLS%
rd /S /Q %T%\cmail
echo.

echo CURL
move /Y %T%\curl\curl.exe %TOOLS%
move /Y %T%\curl\libcurl*.dll %TOOLS%
move /Y %T%\curl\curl-ca-bundle.crt %TOOLS%
rd /S /Q %T%\curl
echo.

echo Desktopinfo
mkdir %TOOLS%\desktopinfo 2>nul
move /Y %T%\desktopinfo\Desktopinfo64.exe %TOOLS%\desktopinfo
move /Y %T%\desktopinfo\*.dll %TOOLS%\desktopinfo
move /Y %T%\desktopinfo\*.pdf %TOOLS%\desktopinfo
rd /S /Q %T%\desktopinfo
copy /Y config\desktopinfo.ini %TOOLS%\desktopinfo
echo.

echo DevManView
move /Y %T%\devmanview\*.exe %TOOLS%
rd /S /Q %T%\devmanview
echo.

echo OfflineRegistryFinder
move /Y %T%\offlineregistryfinder\*.exe %TOOLS%
rd /S /Q %T%\offlineregistryfinder
copy /Y config\OfflineRegistryFinder.cfg %TOOLS%
echo.

echo MAS
move /Y %T%\mas\mas_aio*.cmd %TOOLS%\mas_aio.cmd
rd /S /Q %T%\mas
echo.

echo NSUDO
move /Y %T%\nsudo\nsudo.exe %TOOLS%
rd /S /Q %T%\nsudo
echo.

echo RDPwrapper
move /Y %T%\rdpwrap\RDP*.exe %TOOLS%
rd /S /Q %T%\rdpwrap
echo.

echo RClone
move /Y %T%\rclone\rclone.exe %TOOLS%
rd /S /Q %T%\rclone
echo.

echo Registry Finder
mkdir %TOOLS%\registryfinder 2>nul
move /Y %T%\registryfinder\RegistryFinder.exe %TOOLS%\registryfinder
move /Y %T%\registryfinder\RegistryFinder.ico %TOOLS%\registryfinder
rd /S /Q %T%\registryfinder
echo.

echo RegScanner
move /Y %T%\regscanner\*.exe %TOOLS%
rd /S /Q %T%\regscanner
echo.

echo Restic
move /Y %T%\restic\*.exe %TOOLS%\restic.exe
rd /S /Q %T%\restic
echo.

echo SetDefaultBrowser
move /Y %T%\SetDefaultBrowser\*.exe %TOOLS%
rd /S /Q %T%\SetDefaultBrowser
echo.

echo ServiWIN
move /Y %T%\serviwin\*.exe %TOOLS%
rd /S /Q %T%\serviwin
echo.

echo ShowKeyPlus
move /Y %T%\showkeyplus\*.exe %TOOLS%
rd /S /Q %T%\showkeyplus
echo.

echo SumatraPDF
move /Y %T%\sumatrapdf\*.exe %TOOLS%\SumatraPDF.exe
rd /S /Q %T%\sumatrapdf
copy /Y config\SumatraPDF-settings.txt %TOOLS%
echo.

echo TCP-optimize script
move /Y %T%\tcpoptimize\*.ps1 %TOOLS%\scripts\tcpoptimize.ps1
rd /S /Q %T%\tcpoptimize
echo.

echo TrID (File identifier)
move /Y %T%\trid\trid.exe %TOOLS%
rd /S /Q %T%\trid
echo.

echo TrID (File identifier DATABASE)
move /Y %T%\triddefs\triddefs.trd %TOOLS%
rd /S /Q %T%\triddefs
echo.

echo VIM
move /Y %T%\vim\vim.exe %TOOLS%
rd /S /Q %T%\vim
rem create symbolic link ...
mklink %TOOLS%\vi.exe %TOOLS%\vim.exe 2>nul
echo.

echo wGET
move /Y %T%\wget\wget.exe %TOOLS%
rd /S /Q %T%\wget
move /Y %T%\wgetdeps\*.dll %TOOLS%
rd /S /Q %T%\wgetdeps
echo.

echo WinSCP
move /Y %T%\winscp\*.exe %TOOLS%
rd /S /Q %T%\winscp
echo.

echo WUB - Windows update blocker
move /Y %T%\wub\wub_x64.exe %TOOLS%\wub.exe
rd /S /Q %T%\wub
echo.

echo UWT - Ultimate Windows Tweaker
mkdir %TOOLS%\uwt 2>nul
move /Y %T%\uwt\*.exe %TOOLS%\uwt\uwt.exe
move /Y %T%\uwt\*.dll %TOOLS%\uwt
rd /S /Q %T%\uwt
echo.

echo +++++++++++++++++++++++++
echo ++++ CrystalDiskInfo ++++
echo +++++++++++++++++++++++++

if NOT EXIST %SOFTWARE%\diskinfo.zip (
  echo WARNING: %SOFTWARE%\diskinfo.zip not found!
) else (
  echo unpacking diskinfo.zip ...
  %TOOLS%\7z x -y -aoa -o%TOOLS%\diskinfo %SOFTWARE%\diskinfo.zip 1>nul
  rd /S /Q %TOOLS%\diskinfo\License 2>nul
  del /F /Q %TOOLS%\diskinfo\Readme.txt
  del /F /Q %TOOLS%\diskinfo\DiskInfo32.exe
  del /F /Q %TOOLS%\diskinfo\DiskInfoA64.exe
  rd /S /Q %T%\diskinfo 2>nul
)
echo.

echo +++++++++++++++++++++++
echo ++++ Android tools ++++
echo +++++++++++++++++++++++

if NOT EXIST %SOFTWARE%\android.zip (
  echo WARNING: %SOFTWARE%\android.zip not found!
) else (
  echo unpacking android.zip ...
  %TOOLS%\7z x -y -aoa -o%TOOLS% %SOFTWARE%\android.zip 1>nul
  rd /S /Q %TOOLS%\android 2>nul
  move /Y %TOOLS%\platform-tools %TOOLS%\android
)
echo.

echo ++++++++++++++++++++++
echo ++++ Sysinternals ++++
echo ++++++++++++++++++++++

if NOT EXIST %SOFTWARE%\sysinternals.zip (
  echo WARNING: %SOFTWARE%\sysinternals.zip not found!
) else (

  echo unpacking sysinternals.zip ...
  mkdir %T%\sysinternals 2>nul
  %TOOLS%\7z e -y -aoa -o%T%\sysinternals %SOFTWARE%\sysinternals.zip 1>nul

  echo cleanup of [ %TOOLS%\sysinternals ]
  rd /S /Q %TOOLS%\sysinternals 2>nul
  mkdir %TOOLS%\sysinternals 2>nul

  for %%S in (

  autoruns
  procexp
  tcpview
  vmmap
  zoomit

  ) do (
  
    echo working on [ %%S ] ...
    move /Y %T%\sysinternals\%%S* %TOOLS%\sysinternals

  )

  rd /S /Q %T%\sysinternals 2>nul

)
echo.

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

