@echo off
setlocal
chcp 65001 >nul

:: ========================================================
::   Create Desktop Shortcuts Script
::   Target: Current application folder
:: ========================================================

:: 1. Define paths relative to this script
set "SCRIPT_DIR=%~dp0"
:: Remove trailing backslash
set "SCRIPT_DIR=%SCRIPT_DIR:~0,-1%"

echo Detecting current application folder...

if exist "%SCRIPT_DIR%\一手P3.exe" (
    echo [Mode] Running inside application folder.
    set "EXE_PATH=%SCRIPT_DIR%\一手P3.exe"
    set "DATA_PATH=%SCRIPT_DIR%\users\P3"
    set "WORK_DIR=%SCRIPT_DIR%"
    goto :CheckDone
)

:: Error: Application not found
echo [ERROR] Application not found!
echo Please ensure '一手P3.exe' is in the same folder as this script.
pause
exit /b 1

:CheckDone
echo Target App:  %EXE_PATH%
echo Target Data: %DATA_PATH%
echo.

:: 3. Create Shortcuts using PowerShell
echo Creating shortcuts on Desktop...

:: PowerShell command to create shortcut for EXE
powershell -NoProfile -Command "$WS = New-Object -ComObject WScript.Shell; $Desktop = $WS.SpecialFolders.Item('Desktop'); $S = $WS.CreateShortcut($Desktop + '\一手选体.lnk'); $S.TargetPath = '%EXE_PATH%'; $S.WorkingDirectory = '%WORK_DIR%'; $S.WindowStyle = 1; $S.Description = '一手选体 - 体彩排列三选号平台'; $S.Save(); Write-Host 'Created: 一手选体.lnk'"

:: PowerShell command to create shortcut for P3 Data Directory
if not exist "%DATA_PATH%" (
    mkdir "%DATA_PATH%" >nul 2>nul
)
if exist "%DATA_PATH%" (
    powershell -NoProfile -Command "$WS = New-Object -ComObject WScript.Shell; $Desktop = $WS.SpecialFolders.Item('Desktop'); $S = $WS.CreateShortcut($Desktop + '\一手选体P3数据.lnk'); $S.TargetPath = '%DATA_PATH%'; $S.Description = '一手选体 P3数据目录'; $S.Save(); Write-Host 'Created: 一手选体P3数据.lnk'"
) else (
    echo [WARN] Data directory not found: %DATA_PATH%
    echo Skipping data folder shortcut.
)

echo.
echo ========================================================
echo   Shortcuts created successfully!
echo ========================================================
echo.
pause
