@echo off
set TARGET=C:\AI

where uv >nul 2>&1
if errorlevel 1 (
	powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
	echo Installed... uv! Restart script! >&2
	exit /b 1
)

where git >nul 2>&1
if errorlevel 1 (
	winget install -e --id Git.Git --accept-source-agreements --accept-package-agreements
	echo Installed... git! Restart script! >&2
	exit /b 2
)

if not exist "%TARGET%" (
	git clone https://github.com/Comfy-Org/ComfyUI.git "%TARGET%\ComfyUI"
	cd /d "%TARGET%\ComfyUI\custom_nodes"
	REM git clone https://github.com/ltdrdata/ComfyUI-Manager.git
	REM git clone https://github.com/rgthree/rgthree-comfy.git
	git clone https://github.com/city96/ComfyUI-GGUF.git
	git clone https://github.com/liusida/ComfyUI-Login.git
)

if exist "%TARGET%\ComfyUI\models\" (
	cd /d "%TARGET%\ComfyUI\models"
	if not exist "checkpoints\v1-5-pruned-emaonly-fp16.safetensors" (
		curl --output-dir checkpoints -JLOR https://huggingface.co/Comfy-Org/stable-diffusion-v1-5-archive/resolve/main/v1-5-pruned-emaonly-fp16.safetensors
	)
	if not exist "diffusion_models\flux-2-klein-4b-fp8.safetensors" (
		curl --output-dir diffusion_models -JLOR https://huggingface.co/black-forest-labs/FLUX.2-klein-4b-fp8/resolve/main/flux-2-klein-4b-fp8.safetensors
	)
	if not exist "text_encoders\qwen_3_4b.safetensors" (
		curl --output-dir text_encoders -JLOR https://huggingface.co/Comfy-Org/z_image_turbo/resolve/main/split_files/text_encoders/qwen_3_4b.safetensors
	)
	if not exist "vae\flux2-vae.safetensors" (
		curl --output-dir vae -JLOR https://huggingface.co/Comfy-Org/flux2-dev/resolve/main/split_files/vae/flux2-vae.safetensors
	)
) else (
	echo Error: No model directory! >&2
	exit /b 3
)