@echo off
call check-for-admin
if %ERRORLEVEL% neq 0 exit /b

set T=%SystemDrive%\TEMP
set TOOLS=%SystemDrive%\tools
set CONFIG=config\office2019-standard.xml
set ARCHIVE=..\software\office2019-standard.7z
set STARTMENU="%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs"

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

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

echo unpacking office files ...
%TOOLS%\7z x -y -aoa -o%T% %ARCHIVE%

echo starting MS-Office setup ...
@echo on
%TOOLS%\officedeploymenttool.exe /configure %CONFIG%
@echo off

echo TEMP cleanup ...
rd /S /Q %T%\Office 2>nul

echo renaming folder in startmenu ...
move /Y %STARTMENU%\"Microsoft Office Tools" %STARTMENU%\"Microsoft Office" 2>nul

echo moving links in startmenu ...
move /Y %STARTMENU%\Word.lnk %STARTMENU%\"Microsoft Office" 2>nul
move /Y %STARTMENU%\Excel.lnk %STARTMENU%\"Microsoft Office" 2>nul
move /Y %STARTMENU%\PowerPoint.lnk %STARTMENU%\"Microsoft Office" 2>nul

echo installing desktop icons ...
copy /Y %STARTMENU%\"Microsoft Office\Word.lnk" %PUBLIC%\Desktop
copy /Y %STARTMENU%\"Microsoft Office\Excel.lnk" %PUBLIC%\Desktop
copy /Y %STARTMENU%\"Microsoft Office\PowerPoint.lnk" %PUBLIC%\Desktop

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

echo cleaning startmenu ...
del /F /Q /A %STARTMENU%\"Microsoft Office\Telemetry*.lnk" 2>nul
del /F /Q /A %STARTMENU%\"Microsoft Office\Office Upload Center.lnk" 2>nul

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

rem set filetypes ...
if EXIST ..\scripts\set-filetypes.cmd (
  call ..\scripts\set-filetypes.cmd
)

pause
