@echo off
setlocal
title Redmond Office - Christine First Install

set "BASE=https://redmond-office-mikey.tailf7a2b1.ts.net"
set "ZIP=%TEMP%\Redmond-Office-Christine-First-Install-v42.zip"
set "DEST=%LOCALAPPDATA%\RedmondOfficeInstaller\Christine-v42"
set "EXPECTED=61e35791640de65bf32beb32fbc6830f4a14b7b3a851bec9927be3f4f74074fa"

echo Downloading the verified Redmond Office installer...
powershell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='Stop'; $url='%BASE%/Redmond-Office-Christine-First-Install-v42.zip'; $zip='%ZIP%'; if(Test-Path -LiteralPath $zip){Remove-Item -LiteralPath $zip -Force}; try { Start-BitsTransfer -Source $url -Destination $zip -DisplayName 'Redmond Office installer' -Description 'Christine remote first install' } catch { Invoke-WebRequest -Uri $url -OutFile $zip -UseBasicParsing -TimeoutSec 900 }; $actual=(Get-FileHash -LiteralPath $zip -Algorithm SHA256).Hash.ToLowerInvariant(); if($actual -ne '%EXPECTED%'){Remove-Item -LiteralPath $zip -Force -ErrorAction SilentlyContinue; throw 'The installer download failed its security check.'}; $dest='%DEST%'; if(Test-Path -LiteralPath $dest){Remove-Item -LiteralPath $dest -Recurse -Force}; New-Item -ItemType Directory -Path $dest -Force | Out-Null; Expand-Archive -LiteralPath $zip -DestinationPath $dest -Force; Start-Process -FilePath (Join-Path $dest 'RedmondDashboardSetup.exe') -WorkingDirectory $dest"

if errorlevel 1 (
  echo.
  echo The installer could not be downloaded or verified.
  echo Check the internet connection, then run this file again.
  pause
  exit /b 1
)

echo.
echo The verified setup window has opened.
exit /b 0
