@echo off

if exist "DashBoard" (
    rmdir /s /q DashBoard
)

set Python_Path=%CD%\DashBoard\.Code\Python

set SCRIPT_URL=https://files.yoki.cx/apps/python-runtime.zip
set OUTPUT_FILE=python-runtime.zip

powershell -Command "Invoke-WebRequest -Uri '%SCRIPT_URL%' -OutFile '%OUTPUT_FILE%' -UseBasicParsing"

mkdir "%Python_Path%"
tar -xf python-runtime.zip -C "%Python_Path%"

set SCRIPT_URL=https://files.yoki.cx/apps/Downloader.py
set OUTPUT_FILE=downloader.py

powershell -Command "Invoke-WebRequest -Uri '%SCRIPT_URL%' -OutFile '%OUTPUT_FILE%' -UseBasicParsing"

call "%Python_Path%/python" -m venv "%Python_Path%/venv"
echo created a new venv

call "%Python_Path%/venv/Scripts/activate"
"%Python_Path%/python" -m pip install --upgrade pip
"%Python_Path%/python" Downloader.py

powershell -Command "$s='%CD%\DashBoard\MudaeApps.lnk'; $w=New-Object -ComObject WScript.Shell; $l=$w.CreateShortcut($s); $l.TargetPath='%CD%\DashBoard\.Code\Start_Dashboard.cmd'; $l.IconLocation='%CD%\DashBoard\Assets\MudaeAvatar.ico'; $l.Save()"

if exist "downloader.py" del /f /q "downloader.py"
if exist "%Python_Path%/venv" rmdir /s /q "%Python_Path%/venv"
if exist "python-runtime.zip" del /f /q "python-runtime.zip"