@echo off
setlocal

rem Check for admin privileges
net session >nul 2>&1
if %ERRORLEVEL% NEQ 0 (
    echo Error: This script requires administrator privileges.
    echo Please right-click the script and select "Run as administrator".
    echo Press any key or CTRL+C to exit...
    pause > nul 
    goto :EOF
)

echo ================================================
echo WARNING: SECURITY NOTICE
echo ================================================
echo The Indeo codec is an older video codec that has known security 
echo vulnerabilities. Microsoft has removed native support in newer
echo Windows versions for security reasons.
echo.
echo Only install this codec if you accept this risk.
echo.
echo Press any key to continue or CTRL+C to cancel...
pause > nul

echo Checking system for Indeo video codec components...

rem Check if SysWOW64 directory exists
if not exist "%SystemRoot%\SysWOW64" (
    echo Error: This system appears to be running 32-bit Windows.
    echo This script is designed for 64-bit Windows systems only.
    echo Press any key or CTRL+C to exit...
    pause > nul
    goto :EOF
)

rem Check if regsvr32 exists
if not exist "%SystemRoot%\System32\regsvr32.exe" (
    if not exist "%SystemRoot%\SysWOW64\regsvr32.exe" (
        echo Error: regsvr32 utility not found.
        if exist "%SystemRoot%\SysWOW64\ir50_32.dll" (
            echo The Indeo codec DLL file ir50_32.dll is present, but cannot be registered.
            echo To register the DLL manually in Windows 11:
            echo 1. Click Start, type "cmd", right-click on "Command Prompt" and select "Run as administrator"
            echo 2. In the command prompt window, type: cd %%SystemRoot%%\SysWOW64 and hit enter
            echo 3. In the command prompt window, type: regsvr32 ir50_32.dll and hit enter
            echo You should see a pop-up that the DLL was registered successfully. If not, please reach out for help within the Discord.
        ) else (
            echo The Indeo codec DLL file ir50_32.dll is also missing.
        )
        echo Press any key or CTRL+C to exit...
        pause > nul
        goto :EOF
    )
)

rem Check if ir50_32.dll exists
if not exist "%SystemRoot%\SysWOW64\ir50_32.dll" (
    echo Error: ir50_32.dll not found in %%SystemRoot%%\SysWOW64.
    echo The Indeo video codec DLL file is missing.
    echo regsvr32 exists but cannot register a missing DLL.
    echo Press any key or CTRL+C to exit...
    pause > nul
    goto :EOF
)

rem If all checks pass, register the DLL
echo All components found. Registering Indeo video codec...

cd /d %SystemRoot%\SysWOW64
regsvr32 ir50_32.dll
if %ERRORLEVEL% NEQ 0 (
    echo Error: Failed to register ir50_32.dll. Error code: %ERRORLEVEL%
    echo Possible issues:
    echo - File may be corrupted
    echo - Windows security policy may be blocking registration
    echo - Another system issue is preventing registration
    echo Press any key or CTRL+C to exit...
    pause > nul
    exit /b %ERRORLEVEL%
) else (
    echo Successfully registered ir50_32.dll
)

echo Done. Press any button to continue.

pause > nul
exit /b %ERRORLEVEL%

exit /b 0