Update HMCLauncher.sh (#3265)

* Update HMCLauncher.sh

* update

* update

---------

Co-authored-by: Glavo <zjx001202@gmail.com>
This commit is contained in:
Zkitefly
2025-01-23 13:17:33 +08:00
committed by GitHub
parent c5e7ee8aef
commit 0562042218

View File

@@ -58,17 +58,42 @@ else
_HMCL_VM_OPTIONS="-XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=15"
fi
function show_warning_console() {
echo -e "\033[1;31m$1\033[0m" >&2
}
function show_warning_dialog() {
if [ -n "$3" ]; then
if [ -n "$(command -v xdg-open)" ]; then
if [ -n "$(command -v zenity)" ]; then
zenity --question --title="$1" --text="$2" && xdg-open "$3"
elif [ -n "$(command -v kdialog)" ]; then
kdialog --title "$1" --warningyesno "$2" && xdg-open "$3"
fi
fi
else
if [ -n "$(command -v zenity)" ]; then
zenity --info --title="$1" --text="$2"
elif [ -n "$(command -v kdialog)" ]; then
kdialog --title "$1" --msgbox "$2"
fi
fi
}
function show_warning() {
show_warning_console "$1: $2"
show_warning_dialog "$1" "$2"
}
# First, find Java in HMCL_JAVA_HOME
if [ -n "${HMCL_JAVA_HOME+x}" ]; then
if [ -x "$HMCL_JAVA_HOME/bin/$_HMCL_JAVA_EXE_NAME" ]; then
exec "$HMCL_JAVA_HOME/bin/$_HMCL_JAVA_EXE_NAME" $_HMCL_VM_OPTIONS -jar "$_HMCL_PATH"
else
if [ "$_HMCL_USE_CHINESE" == true ]; then
echo "环境变量 HMCL_JAVA_HOME 的值无效,请设置为合法的 Java 路径。" 1>&2
echo "你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。" 1>&2
show_warning "错误" "环境变量 HMCL_JAVA_HOME 的值无效,请设置为合法的 Java 路径。\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。"
else
echo "The value of the environment variable HMCL_JAVA_HOME is invalid, please set it to a valid Java path." 1>&2
echo "You can visit the https://docs.hmcl.net/help.html page for help." 1>&2
show_warning "Error" "The value of the environment variable HMCL_JAVA_HOME is invalid, please set it to a valid Java path.\nYou can visit the https://docs.hmcl.net/help.html page for help."
fi
exit 1
fi
@@ -126,27 +151,27 @@ fi
case "$_HMCL_OS-$_HMCL_ARCH" in
windows-x86|windows-x86_64|windows-arm64|linux-x86|linux-x86_64|linux-arm32|linux-arm64|linux-riscv64|linux-loongarch64|macos-x86_64|macos-arm64)
if [ "$_HMCL_USE_CHINESE" == true ]; then
echo "运行 HMCL 需要 Java 运行时环境,请安装 Java 并设置环境变量后重试。" 1>&2
echo "https://docs.hmcl.net/downloads/$_HMCL_DOWNLOAD_PAGE_OS/$_HMCL_HMCL_ARCH.html" 1>&2
echo "你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。" 1>&2
else
echo "The Java runtime environment is required to run HMCL. " 1>&2
echo "Please install Java and set the environment variables and try again." 1>&2
echo "https://docs.hmcl.net/downloads/$_HMCL_DOWNLOAD_PAGE_OS/$_HMCL_HMCL_ARCH.html" 1>&2
echo "You can visit the https://docs.hmcl.net/help.html page for help." 1>&2
fi
;;
*)
if [ "$_HMCL_USE_CHINESE" == true ]; then
echo "运行 HMCL 需要 Java 运行时环境,请安装 Java 并设置环境变量后重试。" 1>&2
echo "你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。" 1>&2
else
echo "The Java runtime environment is required to run HMCL. " 1>&2
echo "Please install Java and set the environment variables and try again." 1>&2
echo "You can visit the https://docs.hmcl.net/help.html page for help." 1>&2
fi
_HMCL_JAVA_DOWNLOAD_PAGE="https://docs.hmcl.net/downloads/$_HMCL_DOWNLOAD_PAGE_OS/$_HMCL_ARCH.html"
;;
esac
if [ "$_HMCL_USE_CHINESE" == true ]; then
_HMCL_WARNING_MESSAGE="运行 HMCL 需要 Java 运行时环境,请安装 Java 并设置环境变量后重试。"
if [ -n "$_HMCL_JAVA_DOWNLOAD_PAGE" ]; then
show_warning_console "错误: $_HMCL_WARNING_MESSAGE\n你可以前往此处下载:\n$_HMCL_JAVA_DOWNLOAD_PAGE"
show_warning_dialog "错误" "$_HMCL_WARNING_MESSAGE\n\n是否要前往 Java 下载页面?" "$_HMCL_JAVA_DOWNLOAD_PAGE"
else
show_warning "错误" "$_HMCL_WARNING_MESSAGE\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。"
fi
else
_HMCL_WARNING_MESSAGE="The Java runtime environment is required to run HMCL.\nPlease install Java and set the environment variables and try again."
if [ -n "$_HMCL_JAVA_DOWNLOAD_PAGE" ]; then
show_warning_console "Error: $_HMCL_WARNING_MESSAGE\nYou can download it from here:\n$_HMCL_JAVA_DOWNLOAD_PAGE"
show_warning_dialog "Error" "$_HMCL_WARNING_MESSAGE\n\nDo you want to go to the Java download page?" "$_HMCL_JAVA_DOWNLOAD_PAGE"
else
show_warning "Error" "$_HMCL_WARNING_MESSAGE\nYou can visit the https://docs.hmcl.net/help.html page for help."
fi
fi
exit 1