#!/bin/bash
# 尝试下载 Cubism SDK for Native (含 Core 库)
cd /tmp
echo "=== Try downloading Cubism SDK for Native ==="

# Live2D 官方下载通常用这种 URL 模式
# 先尝试常见的下载链接
URLS=(
  "https://cubism.live2d.com/sdk-native/bin/CubismSdkForNative.zip"
  "https://www.live2d.com/download/cubism-sdk/download-native/?agree=true"
  "https://download.live2d.com/cubism-sdk/native/CubismSdkForNative.zip"
)

for url in "${URLS[@]}"; do
  echo "Trying: $url"
  wget --timeout=15 --tries=1 -q "$url" -O test_download.bin 2>&1
  if [ $? -eq 0 ]; then
    SIZE=$(stat -c%s test_download.bin 2>/dev/null || echo 0)
    echo "  Downloaded: $SIZE bytes"
    if [ "$SIZE" -gt 100000 ]; then
      echo "  Looks like a real file! Checking type..."
      file test_download.bin
      mv test_download.bin CubismSdkForNative.zip
      echo "  SUCCESS: saved as CubismSdkForNative.zip"
      exit 0
    fi
  else
    echo "  Failed or too small"
  fi
  rm -f test_download.bin
done

echo "=== Direct URL attempts failed ==="
echo "Checking actual download page for hidden links..."
curl -sL "https://www.live2d.com/zh-CHS/sdk/download/native/" 2>/dev/null | grep -oiE 'href="[^"]*\.zip[^"]*"' | head -10
echo "---"
curl -sL "https://www.live2d.com/download/cubism-sdk/download-native/" 2>/dev/null | grep -oiE 'href="[^"]*download[^"]*"' | head -10

echo "=== DONE ==="
