@echo off setlocal enabledelayedexpansion title Windows Performance Optimizer cd /d "%~dp0" :: ── Require Administrator ──────────────────────────────────────────────────── net session >nul 2>&1 if %errorLevel% neq 0 ( powershell -Command "Start-Process -FilePath '%~f0' -Verb RunAs" exit /b ) echo. echo ============================================ echo Windows Performance Optimizer echo ============================================ echo. :: ── Locate Source Code ─────────────────────────────────────────────────────── set INSTALL_DIR=%LOCALAPPDATA%\Programs\WindowsOptimizer set APP_SCRIPT=%INSTALL_DIR%\WindowsOptimizer.py :: If bat is already sitting next to the source (dev/cloned repo), use that if exist "%~dp0WindowsOptimizer.py" ( set APP_SCRIPT=%~dp0WindowsOptimizer.py goto :find_python ) :: Already installed — skip download if exist "%APP_SCRIPT%" goto :find_python :: ── Download Source from GitHub ────────────────────────────────────────────── echo Downloading Windows Optimizer from GitHub... echo. set REPO_ZIP=%TEMP%\WindowsOptimizer.zip set REPO_EXTRACT=%TEMP%\WindowsOptimizer_src powershell -Command "& { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri 'https://github.com/TR4IS/WindowsOptimizer/archive/refs/heads/main.zip' -OutFile '%REPO_ZIP%' }" if not exist "%REPO_ZIP%" ( echo ERROR: Download failed. Check your internet connection. pause & exit /b 1 ) echo Extracting... if exist "%REPO_EXTRACT%" rd /s /q "%REPO_EXTRACT%" powershell -Command "Expand-Archive -Path '%REPO_ZIP%' -DestinationPath '%REPO_EXTRACT%' -Force" if not exist "%REPO_EXTRACT%\WindowsOptimizer-main\WindowsOptimizer.py" ( echo ERROR: Extraction failed or repo structure changed. pause & exit /b 1 ) if not exist "%INSTALL_DIR%" mkdir "%INSTALL_DIR%" xcopy /e /y /q "%REPO_EXTRACT%\WindowsOptimizer-main\*" "%INSTALL_DIR%\" >nul del /f /q "%REPO_ZIP%" 2>nul rd /s /q "%REPO_EXTRACT%" 2>nul echo Source installed to: %INSTALL_DIR% echo. :: ── Find Python ────────────────────────────────────────────────────────────── :find_python set PYTHON_EXE= python --version >nul 2>&1 if %errorLevel% equ 0 ( set PYTHON_EXE=python & goto :found_python ) py --version >nul 2>&1 if %errorLevel% equ 0 ( set PYTHON_EXE=py & goto :found_python ) for %%D in ( "%LOCALAPPDATA%\Programs\Python\Python313\python.exe" "%LOCALAPPDATA%\Programs\Python\Python312\python.exe" "%LOCALAPPDATA%\Programs\Python\Python311\python.exe" "%LOCALAPPDATA%\Programs\Python\Python310\python.exe" "%LOCALAPPDATA%\Programs\Python\Python39\python.exe" "%ProgramFiles%\Python313\python.exe" "%ProgramFiles%\Python312\python.exe" "%ProgramFiles%\Python311\python.exe" "%ProgramFiles%\Python310\python.exe" "C:\Python312\python.exe" "C:\Python311\python.exe" ) do ( if exist %%D ( set PYTHON_EXE=%%D & goto :found_python ) ) :: ── Python Not Found: Download and Install ─────────────────────────────────── echo Python not found. Downloading from python.org... echo. set PYTHON_INSTALLER=%TEMP%\python_installer.exe powershell -Command "& { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri 'https://www.python.org/ftp/python/3.11.9/python-3.11.9-amd64.exe' -OutFile '%PYTHON_INSTALLER%' }" if not exist "%PYTHON_INSTALLER%" ( echo ERROR: Could not download Python. Check your internet connection. pause & exit /b 1 ) echo Installing Python 3.11, please wait... "%PYTHON_INSTALLER%" /quiet InstallAllUsers=0 PrependPath=1 Include_test=0 Include_launcher=1 del /f /q "%PYTHON_INSTALLER%" 2>nul for %%D in ( "%LOCALAPPDATA%\Programs\Python\Python311\python.exe" "%LOCALAPPDATA%\Programs\Python\Python312\python.exe" "%LOCALAPPDATA%\Programs\Python\Python313\python.exe" ) do ( if exist %%D ( set PYTHON_EXE=%%D & goto :found_python ) ) echo ERROR: Could not locate Python after installation. Restart and try again. pause & exit /b 1 :found_python for /f "tokens=*" %%V in ('"%PYTHON_EXE%" --version 2^>^&1') do echo Python : %%V echo Script : %APP_SCRIPT% echo. :: ── Install Dependencies ───────────────────────────────────────────────────── echo Checking dependencies... "%PYTHON_EXE%" -m pip install --quiet --upgrade customtkinter echo Ready. echo. :: ── Launch ─────────────────────────────────────────────────────────────────── echo Launching... echo. "%PYTHON_EXE%" "%APP_SCRIPT%" if %errorLevel% neq 0 ( echo. echo The application exited with an error ^(code %errorLevel%^). pause ) endlocal