@echo off setlocal enabledelayedexpansion set GITHUB_API=https://api.github.com/repos/Lameguy64/PSn00bSDK/releases/latest set GITHUB_RELEASES=https://github.com/Lameguy64/PSn00bSDK/releases set DEFAULT_INSTALL_DIR=C:\psn00bsdk set VERSION_FILE=.version :main cls echo ========================================== echo PSn00bSDK Manager (Windows) echo ========================================== echo. echo Please select an action: echo. echo 1) Install PSn00bSDK echo 2) Uninstall PSn00bSDK echo 3) Check for updates echo 4) Exit echo. set /p choice="Enter your choice [1-4]: " echo. if "%choice%"=="1" goto install if "%choice%"=="2" goto uninstall if "%choice%"=="3" goto check_updates if "%choice%"=="4" goto exit_script echo [ERROR] Invalid choice. Please enter a number between 1 and 4. echo. pause goto main :install echo. set /p version="Enter version to install (leave blank for latest, e.g., 0.24): " echo. set /p install_dir="Enter installation directory [%DEFAULT_INSTALL_DIR%]: " if "%install_dir%"=="" set install_dir=%DEFAULT_INSTALL_DIR% if defined version ( set version_clean=%version% echo [INFO] Installing version: %version_clean% ) else ( call :get_latest_version latest_version if !latest_version!==FAILED ( echo [ERROR] Failed to get latest version from GitHub echo. pause goto main ) set version_clean=!latest_version:~1! echo [INFO] Installing latest version: !version_clean! ) call :install_sdk %install_dir% %version_clean% if errorlevel 1 ( echo. pause goto main ) call :setup_environment %install_dir% call :verify_installation %install_dir% call :print_post_install %install_dir% echo. pause goto main :uninstall echo. set /p install_dir="Enter installation directory [%DEFAULT_INSTALL_DIR%]: " if "%install_dir%"=="" set install_dir=%DEFAULT_INSTALL_DIR% call :uninstall_sdk %install_dir% if errorlevel 1 ( echo. pause goto main ) call :remove_environment echo. echo [INFO] Uninstallation complete! echo [INFO] Please restart your terminal for environment changes to take effect echo. pause goto main :check_updates echo. set /p install_dir="Enter installation directory [%DEFAULT_INSTALL_DIR%]: " if "%install_dir%"=="" set install_dir=%DEFAULT_INSTALL_DIR% if not exist "%install_dir%" ( echo [WARN] PSn00bSDK is not installed in: %install_dir% set /p install_dir="Enter installation directory: " if not exist "%install_dir%" ( echo [ERROR] Directory not found: %install_dir% echo. pause goto main ) ) echo [INFO] Checking for latest release from GitHub... set installed_version= if exist "%install_dir%\%VERSION_FILE%" ( set /p installed_version=<"%install_dir%\%VERSION_FILE%" ) call :get_latest_version latest_version if !latest_version!==FAILED ( echo [ERROR] Failed to get latest version from GitHub echo. pause goto main ) set latest_version_num=!latest_version:~1! echo. echo ========================================== echo Version Check Results echo ========================================== echo. if defined installed_version ( echo Installed version: %installed_version% ) else ( echo Installed version: Not detected ) echo Latest version: !latest_version_num! echo. if "%installed_version%"=="!latest_version_num!" ( echo [INFO] You are running the latest version! ) else if not defined installed_version ( echo [WARN] Could not detect installed version ) else ( echo [INFO] A newer version is available! echo. echo Download the latest version from: echo %GITHUB_RELEASES% ) echo ========================================== echo. pause goto main :get_latest_version setlocal set latest_version=FAILED for /f "delims=" %%i in ('powershell -Command "& {$response = Invoke-WebRequest -Uri '%GITHUB_API%' -UseBasicParsing; $tag = ($response.Content ^| ConvertFrom-Json).tag_name; Write-Host $tag}" 2^>nul') do ( set latest_version=%%i ) if defined latest_version ( endlocal & set %~1=%latest_version% ) else ( endlocal & set %~1=FAILED ) exit /b 0 :install_sdk set install_dir=%~1 set version=%~2 if exist "%install_dir%" ( echo [WARN] Installation directory already exists: %install_dir% set /p confirm="Do you want to overwrite it? (y/N): " if /i not "%confirm%"=="y" ( echo [ERROR] Installation cancelled. exit /b 1 ) rmdir /s /q "%install_dir%" ) set file_name=PSn00bSDK-%version%-win32.zip set download_url=https://github.com/Lameguy64/PSn00bSDK/releases/download/v%version%/%file_name% set temp_dir=%TEMP%\psn00bsdk_temp if exist "%temp_dir%" rmdir /s /q "%temp_dir%" mkdir "%temp_dir%" echo [INFO] Downloading PSn00bSDK v%version% (Windows)... echo [INFO] URL: %download_url% powershell -Command "Invoke-WebRequest -Uri '%download_url%' -OutFile '%temp_dir%\%file_name%'" 2>nul if errorlevel 1 ( echo [ERROR] Failed to download PSn00bSDK rmdir /s /q "%temp_dir%" exit /b 1 ) echo [INFO] Extracting SDK to temporary directory... powershell -Command "Expand-Archive -Path '%temp_dir%\%file_name%' -DestinationPath '%temp_dir%'" 2>nul if errorlevel 1 ( echo [ERROR] Failed to extract SDK rmdir /s /q "%temp_dir%" exit /b 1 ) for /d %%d in ("%temp_dir%\PSn00bSDK-*") do ( set extracted_dir=%%d ) if not defined extracted_dir ( echo [ERROR] Failed to find extracted SDK directory rmdir /s /q "%temp_dir%" exit /b 1 ) echo [INFO] Installing PSn00bSDK to: %install_dir% if not exist "%install_dir%" mkdir "%install_dir%" xcopy /s /e /i /y "!extracted_dir!\*" "%install_dir%\" >nul if errorlevel 1 ( echo [ERROR] Failed to copy files rmdir /s /q "%temp_dir%" exit /b 1 ) echo [INFO] Creating version file... echo %version% > "%install_dir%\%VERSION_FILE%" rmdir /s /q "%temp_dir%" echo [INFO] Installation completed successfully! exit /b 0 :setup_environment set install_dir=%~1 set bin_dir=%install_dir%\bin set libs_dir=%install_dir%\lib\libpsn00b echo [INFO] Configuring environment variables... for /f "tokens=2*" %%a in ('reg query "HKCU\Environment" /v PATH 2^>nul') do ( set current_path=%%b ) if not defined current_path set current_path= set psn00b_path=%bin_dir% set psn00b_libs=%libs_dir% echo %psn00b_path%| findstr /C:"%current_path%" >nul if errorlevel 1 ( setx PATH "%psn00b_path%;%current_path%" >nul echo [INFO] PATH updated successfully ) else ( echo [WARN] PATH already contains PSn00bSDK ) setx PSN00BSDK_LIBS "%psn00b_libs%" >nul echo [INFO] PSN00BSDK_LIBS set successfully echo [INFO] Please restart your terminal for environment changes to take effect exit /b 0 :verify_installation set install_dir=%~1 echo [INFO] Verifying installation... if not exist "%install_dir%\bin" ( echo [ERROR] bin directory not found in %install_dir% exit /b 1 ) if not exist "%install_dir%\lib\libpsn00b" ( echo [ERROR] libpsn00b directory not found in %install_dir% exit /b 1 ) echo [INFO] All checks passed! exit /b 0 :print_post_install set install_dir=%~1 echo. echo ========================================== echo PSn00bSDK Installation Complete! echo ========================================== echo. echo Installation directory: %install_dir% echo. echo To complete setup, please: echo 1. Close and reopen your terminal (or restart your computer) echo for environment variables to take effect echo. echo 2. Verify installation by running: echo mipsel-none-elf-gcc --version echo mkpsxiso --help echo. echo 3. Create your first project using the template: echo xcopy /e /i "%install_dir%\share\psn00bsdk\template" "%USERPROFILE%\my_project" echo cd "%USERPROFILE%\my_project" echo cmake --preset default . echo cmake --build ./build echo. echo For more information, see: echo %install_dir%\share\psn00bsdk\doc\README.md echo ========================================== exit /b 0 :uninstall_sdk set install_dir=%~1 if not exist "%install_dir%" ( echo [WARN] Installation directory not found: %install_dir% set /p install_dir="Enter installation directory path: " if not exist "%install_dir%" ( echo [ERROR] Directory not found: %install_dir% exit /b 1 ) ) echo [WARN] This will remove PSn00bSDK from: %install_dir% set /p confirm="Are you sure? (y/N): " if /i not "%confirm%"=="y" ( echo [ERROR] Uninstallation cancelled. exit /b 1 ) rmdir /s /q "%install_dir%" echo [INFO] PSn00bSDK removed successfully! exit /b 0 :remove_environment set install_dir=%install_dir% echo [INFO] Removing PSn00bSDK environment variables... reg query "HKCU\Environment" /v PSN00BSDK_LIBS >nul 2>&1 if not errorlevel 1 ( reg delete "HKCU\Environment" /v PSN00BSDK_LIBS /f >nul 2>&1 echo [INFO] PSN00BSDK_LIBS removed ) for /f "tokens=2*" %%a in ('reg query "HKCU\Environment" /v PATH 2^>nul') do ( set current_path=%%b ) if defined current_path ( set psn00b_path=%DEFAULT_INSTALL_DIR%\bin set new_path=!current_path! set new_path=!new_path:%psn00b_path%;=! set new_path=!new_path:%psn00b_path%=! if not "!new_path!"=="!current_path!" ( reg add "HKCU\Environment" /v PATH /t REG_EXPAND_SZ /d "!new_path!" /f >nul 2>&1 if not errorlevel 1 ( echo [INFO] PATH cleaned ) ) ) exit /b 0 :exit_script echo Exiting... exit /b 0