#!/bin/bash

# 提示用户输入版本号
read -p "请输入 v2rayN 版本号（例如 7.12.5）: " version

# 创建版本文件夹
mkdir -p "$version"
cd "$version" || exit 1

# 定义 GitHub Releases 基础 URL
base_url="https://github.com/2dust/v2rayN/releases/download/${version}"

# Windows 下载链接
windows_files=(
  "v2rayN-windows-64-SelfContained.zip"
  "v2rayN-windows-64-desktop.zip"
  "v2rayN-windows-64.zip"
  "v2rayN-windows-arm64-desktop.zip"
  "v2rayN-windows-arm64.zip"
)

# Linux 下载链接
linux_files=(
  "v2rayN-linux-64.AppImage"
  "v2rayN-linux-64.deb"
  "v2rayN-linux-64.zip"
  "v2rayN-linux-arm64.AppImage"
  "v2rayN-linux-arm64.deb"
  "v2rayN-linux-arm64.zip"
)

# macOS 下载链接
macos_files=(
  "v2rayN-macos-64.dmg"
  "v2rayN-macos-64.zip"
  "v2rayN-macos-arm64.dmg"
  "v2rayN-macos-arm64.zip"
)

echo "开始下载 Windows 版本..."
for file in "${windows_files[@]}"; do
  aria2c -x4 -s4 "${base_url}/${file}"
done

echo "开始下载 Linux 版本..."
for file in "${linux_files[@]}"; do
  aria2c -x4 -s4 "${base_url}/${file}"
done

echo "开始下载 macOS 版本..."
for file in "${macos_files[@]}"; do
  aria2c -x4 -s4 "${base_url}/${file}"
done

echo "下载完成，文件已保存在当前目录下的 ${version} 文件夹。"
