Last active
December 31, 2023 15:12
-
-
Save zkitefly/bba592b410bc3f7666070d9972f78270 to your computer and use it in GitHub Desktop.
HMCL-Snapshot-Update-prs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
REM 指定文件夹名称 | |
set "folder_name=HMCL-Snapshot-Update" | |
REM HMCL-Snapshot-Update-prs.exe 文件名 | |
set "executable_name=HMCL-Snapshot-Update-prs.exe" | |
REM 下载链接 | |
set "download_url=https://rgp.zkitefly.repl.co/https:/raw.githubusercontent.com/burningtnt/HMCL-Snapshot-Update/prs/datas/wrapped-snapshot.json" | |
REM 若不存在 %folder_name% 文件夹,则新建 | |
if not exist "%folder_name%" ( | |
mkdir "%folder_name%" | |
) else ( | |
REM 若存在 %folder_name%,检查文件夹内是否有 HMCL-Snapshot-Update-prs.exe,有就删除 | |
if exist "%folder_name%\%executable_name%" ( | |
del "%folder_name%\%executable_name%" | |
) | |
) | |
REM 使用10次重试下载并解压gzip的 wrapped-snapshot.json 文件 | |
set "retry_count=10" | |
:retry1 | |
curl --compressed -o "%folder_name%\wrapped-snapshot.json" "%download_url%" | |
if %errorlevel% neq 0 ( | |
set /a "retry_count-=1" | |
if %retry_count% gtr 0 goto retry1 | |
echo 下载失败,请检查网络连接。 | |
echo %download_url% | |
exit /b 1 | |
) | |
REM 通过正则表达式提取 "jar" 键的值 | |
for /f "tokens=*" %%i in ('type "%folder_name%\wrapped-snapshot.json" ^| findstr /r /c:"\"jar\":\".*\""') do ( | |
for /f "tokens=2 delims=:" %%j in ("%%i") do set "jar_url=%%~j" | |
) | |
REM 使用10次重试下载并解压gzip的文件 | |
set "retry_count=10" | |
:retry2 | |
curl --compressed -o "%folder_name%\%executable_name%" "%jar_url%" | |
if %errorlevel% neq 0 ( | |
set /a "retry_count-=1" | |
if %retry_count% gtr 0 goto retry2 | |
echo 下载失败,请检查网络连接。 | |
exit /b 1 | |
) | |
REM 清屏 | |
cls | |
REM 执行命令 | |
"%folder_name%\%executable_name%" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# chmod +x HMCL-Snapshot-Update-prs.sh | |
# 指定文件夹名称 | |
folder_name="HMCL-Snapshot-Update" | |
# HMCL-Snapshot-Update-prs.exe 文件名定义 | |
exe_filename="HMCL-Snapshot-Update-prs.exe" | |
# 下载链接 | |
download_url="https://rgp.zkitefly.repl.co/https:/raw.githubusercontent.com/burningtnt/HMCL-Snapshot-Update/prs/datas/wrapped-snapshot.json" | |
# 如果文件夹不存在,则创建 | |
if [ ! -d "$folder_name" ]; then | |
mkdir "$folder_name" | |
else | |
# 如果文件夹存在,尝试删除 HMCL-Snapshot-Update-prs.exe | |
if [ -e "$folder_name/$exe_filename" ]; then | |
rm "$folder_name/$exe_filename" | |
fi | |
fi | |
# 下载 wrapped-snapshot.json 文件,设置重试次数为10次 | |
retry_count=10 | |
while [ $retry_count -gt 0 ]; do | |
wget --compression=gzip -O "$folder_name/wrapped-snapshot.json" "$download_url" | |
if [ $? -eq 0 ]; then | |
break | |
fi | |
((retry_count--)) | |
done | |
# 检查是否成功下载 | |
if [ $retry_count -eq 0 ]; then | |
echo "下载失败,请检查网络连接。" | |
exit 1 | |
fi | |
# 通过正则表达式提取 jar 键的值 | |
jar_url=$(grep -Eo '"jar":\s*"[^"]+"' "$folder_name/wrapped-snapshot.json" | sed 's/"jar":\s*"\(.*\)"/\1/') | |
# 下载 jar 文件,设置重试次数为10次 | |
retry_count=10 | |
while [ $retry_count -gt 0 ]; do | |
wget --compression=gzip -O "$folder_name/$exe_filename" "$jar_url" | |
if [ $? -eq 0 ]; then | |
break | |
fi | |
((retry_count--)) | |
done | |
# 检查是否成功下载 | |
if [ $retry_count -eq 0 ]; then | |
echo "下载失败,请检查网络连接。" | |
exit 1 | |
fi | |
# clear | |
clear | |
# 执行命令 | |
java -jar "$folder_name/$exe_filename" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment