Skip to content

Instantly share code, notes, and snippets.

@engalar
Created July 29, 2023 08:23
Show Gist options
  • Save engalar/b3f8c5b919a83985a122ce8e32e161c9 to your computer and use it in GitHub Desktop.
Save engalar/b3f8c5b919a83985a122ce8e32e161c9 to your computer and use it in GitHub Desktop.
@echo off
chcp 65001
setlocal enabledelayedexpansion
REM 设置常量和依赖项URL
set "CDN_BASE_URL=https://artifacts.rnd.mendix.com"
set "LISTING_URL=https://cdn.mendix.com/listing.txt"
REM 动态获取最新的下载地址
rem 设置网页 URL
set "url=https://mirrors.tuna.tsinghua.edu.cn/Adoptium/11/jdk/x64/windows/"
rem 使用 curl 命令发送 HTTP 请求并将输出提供给 for /f 循环
for /f "delims=" %%i in ('curl -s %url% ^| findstr /i "_hotspot_"') do (
set "web_content=!web_content!%%i"
)
rem 使用 for /f 命令提取 href 属性值
for /f "tokens=5 delims=^= " %%i in ("!web_content!") do (
set "latest_link=%%~i"
goto :download
)
:download
rem 拼接完整的下载链接
set "JDK_URL=%url%%latest_link%"
@REM set "JDK_URL=https://mirrors.tuna.tsinghua.edu.cn/Adoptium/11/jdk/x64/windows/OpenJDK11U-jdk_x64_windows_hotspot_11.0.20_8.msi"
echo 最新的JDK下载地址:%JDK_URL%
set "ADOPTOPENJDK_URL=https://adoptopenjdk.net/releases.html?variant=openjdk11&jvmVariant=hotspot"
set "MENDIX_NATIVE_BUILDER_URL=%CDN_BASE_URL%/native-builders/latest.exe"
set "VCREDIST_2010_URL=https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x64.exe"
set "VCREDIST_2019_URL=https://aka.ms/vs/16/release/vc_redist.x64.exe"
set "GRADLE_URL=https://services.gradle.org/distributions/gradle-7.6-bin.zip"
set "GIT_URL=https://github.com/git-for-windows/git/releases/download/v2.41.0.windows.3/Git-2.41.0.3-64-bit.exe"
set "WINDOWSDESKTOP_RUNTIME_URL=https://download.visualstudio.microsoft.com/download/pr/5681bdf9-0a48-45ac-b7bf-21b7b61657aa/bbdc43bc7bf0d15b97c1a98ae2e82ec0/windowsdesktop-runtime-6.0.5-win-x64.exe"
rem 判断是否存在第一个参数
if "%~1" neq "" (
echo 手动指定下载版本为: %~1
set folder=%~1
call :install_chosen_version
EXIT /B %ERRORLEVEL%
) else (
echo 未提供下载版本参数.
)
REM 开始执行脚本
call :download_listing_file
echo.
echo 请选择一个你想要安装的Studio Pro版本号?
echo [162] 9.9.2.35886
echo 例如你输入162表示安装9.9.2.35886
echo.
call :display_available_versions
echo.
set /p "chose=?"
echo.
set "folder=!var[%chose%]:~0,-7!"
call :install_chosen_version
EXIT /B %ERRORLEVEL%
REM 函数定义
:download_file
if not exist %~2 (
echo 下载文件 %~1 到 %~2
powershell -Command "(New-Object Net.WebClient).DownloadFile('%~1', '%~2')"
) else (
echo 已经存在 %~2
)
EXIT /B 0
:download_listing_file
call :download_file %LISTING_URL% listing.txt
EXIT /B 0
:display_available_versions
set count=0
for /f "tokens=1,2 delims=-" %%a in (listing.txt) do (
if "%%a" == "runtime/mendix" (
set /a count+=1
set "var[!count!]=%%b"
)
)
for /l %%x in (1,1,%count%) do (
echo [%%x] !var[%%x]:~0,-7!
)
EXIT /B 0
:install_chosen_version
echo 你选择安装 !folder!
REM 下载选择的Mendix Studio Pro版本安装文件
call :download_file %CDN_BASE_URL%/modelers/Mendix-%folder%-Setup.exe .\Mendix-%folder%-Setup.exe
REM 其他依赖项的下载
if not exist ./Dependencies (
mkdir Dependencies
)
call :download_file %JDK_URL% ./Dependencies/adoptopenjdk_11_x64.msi
call :download_file %MENDIX_NATIVE_BUILDER_URL% ./Dependencies/mendix_native_mobile_builder.exe
call :download_file %VCREDIST_2010_URL% ./Dependencies/credist2010_x64.exe
call :download_file %VCREDIST_2019_URL% ./Dependencies/credist2019_x64.exe
call :download_file %GRADLE_URL% ./Dependencies/gradle-7.6-bin.zip
call :download_file %GIT_URL% ./Dependencies/git_for_windows_installer.exe
call :download_file %WINDOWSDESKTOP_RUNTIME_URL% ./Dependencies/windowsdesktop-runtime-6.0-x64.exe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment