Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
licyk committed Apr 4, 2024
1 parent c64240d commit 9a8c64f
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 28 deletions.
46 changes: 41 additions & 5 deletions ani2xcur.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ ani_launch_args_manager()
--inf)
ani_launch_args_input="--inf"
;;
--install-win2xcur)
install_win2xcur=1
;;
--remove-win2xcur)
install_win2xcur=2
;;
*)
ani_unknown_args_echo $i
;;
Expand All @@ -135,7 +141,7 @@ ani_args_help()
{
cat<<EOF
使用:
./ani2xcur.sh --help [--set-python-path python_path] [--inf inf_file_path]
./ani2xcur.sh --help [--set-python-path python_path] [--inf inf_file_path] [--install-win2xcur] [--remove-win2xcur]
参数:
--help
Expand All @@ -144,6 +150,10 @@ ani_args_help()
指定 Python 解释器路径。推荐在 Python 虚拟环境中启动 Ani2xcur, 这将可省去使用启动参数指定 Python 路径
--inf inf_file_path
指定 inf 鼠标配置文件路径, 若路径有效, 则 Ani2xcur 将以命令行模式启动, 直接进行鼠标指针转换
--install-win2xcur
安装 win2xcur 核心
--remove-win2xcur
卸载 win2xcur 核心
EOF
}

Expand All @@ -164,12 +174,16 @@ set_inf_file_path()
{
if [ -z "$*" ];then
ani_echo "inf 鼠标指针配置文件路径为空"
ani_echo "取消使用命令行模式, 将启动 Ani2xcur 界面"
sleep 3
else
if [ -f "$@" ];then
ani_echo "指定 inf 鼠标指针配置文件路径: $@"
inf_file_path=$@
else
ani_echo "inf 鼠标指针配置文件路径无效"
ani_echo "取消使用命令行模式, 将启动 Ani2xcur 界面"
sleep 3
fi
fi
}
Expand Down Expand Up @@ -202,6 +216,7 @@ main()
file_format_2="ani"
file_format_3="cur"
use_custom_python_path=1
install_win2xcur=0
# pip镜像源设置
export PIP_INDEX_URL="https://mirrors.cloud.tencent.com/pypi/simple"
export PIP_EXTRA_INDEX_URL="https://mirror.baidu.com/pypi/simple https://mirrors.bfsu.edu.cn/pypi/web/simple https://mirror.nju.edu.cn/pypi/web/simple"
Expand Down Expand Up @@ -230,10 +245,10 @@ main()
# 依赖检查
if [ -z "$ani_python_path" ];then
if python3 --version > /dev/null 2>&1 || python --version > /dev/null 2>&1 ;then # 判断是否有可用的python
if [ ! -z "$(python3 --version 2> /dev/null)" ];then
export ani_python_path=$(which python3)
elif [ ! -z "$(python --version 2> /dev/null)" ];then
if [ ! -z "$(python --version 2> /dev/null)" ];then
export ani_python_path=$(which python)
elif [ ! -z "$(python3 --version 2> /dev/null)" ];then
export ani_python_path=$(which python3)
fi
else
missing_depend_info=1
Expand All @@ -249,6 +264,26 @@ main()
fi
fi

# 检测可用的pip命令
if [ ! -z "$VIRTUAL_ENV" ];then
if [ ! -z "$(python --version 2> /dev/null)" ];then
if ! python -m pip -V > /dev/null 2>&1 ;then
missing_depend_info=1
missing_depend="$missing_depend pip,"
fi
elif [ ! -z "$(python3 --version 2> /dev/null)" ];then
if ! python3 -m pip -V > /dev/null 2>&1 ;then
missing_depend_info=1
missing_depend="$missing_depend pip,"
fi
fi
else
if ! "$ani_python_path" -m pip -V > /dev/null 2>&1 ;then
missing_depend_info=1
missing_depend="$missing_depend pip,"
fi
fi

if [ -z "$inf_file_path" ];then # 未指定inf文件路径
if ! which dialog > /dev/null 2>&1; then
missing_depend_info=1
Expand All @@ -260,6 +295,7 @@ main()
else
ani_echo "寻找 inf 鼠标指针配置文件"
inf_file_path="$(dirname "$inf_file_path")/$(ls -a "$(dirname "$inf_file_path")" | grep \.inf$ | awk 'NR==1')"
ani_echo "inf 鼠标指针配置文件路径: $inf_file_path"
ani_echo "以命令行模式启动 Ani2xcur"
fi
cli_mode=0
Expand All @@ -282,7 +318,7 @@ main()


# 运行目录检查
if && [ ! -d ".git" ] && [ ! -d "modules" ] && [ ! -f "modules/init.sh" ] && [ ! -d "source" ];then
if [ ! -d ".git" ] && [ ! -d "modules" ] && [ ! -f "modules/init.sh" ] && [ ! -d "source" ];then
ani_echo "检测到目录错误"
ani_echo "请进入 Ani2xcur 目录里再运行 Ani2xcur"
ani_echo "退出 Ani2xcur"
Expand Down
27 changes: 27 additions & 0 deletions modules/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@ do
[ ! "$i" = "./modules/init.sh" ] && . ./$i
done

# 安装win2xcur
case $install_win2xcur in
1)
ani_echo "安装 wi2n2xcur 中"
if which win2xcur > /dev/null 2>&1; then
ani_pip install numpy wand win2xcur --upgrade --force-reinstall
else
ani_pip install numpy wand win2xcur --upgrade
fi
if [ $? = 0 ];then
ani_echo "win2xcur 核心安装成功"
else
ani_echo "win2xcur 核心安装成功"
fi
;;
2)
ani_echo "卸载 wi2n2xcur 中"
ani_pip uninstall win2xcur -y
if [ $? = 0 ];then
ani_echo "win2xcur 核心卸载成功"
else
ani_echo "win2xcur 核心卸载成功"
fi
;;
esac

# 启动
if [ $cli_mode = 0 ];then
ani_echo "启动转换"
Expand All @@ -15,4 +41,5 @@ if [ $cli_mode = 0 ];then
ani_echo "退出 Ani2xcur"
else
mainmenu
ani_echo "退出 Ani2xcur"
fi
18 changes: 13 additions & 5 deletions modules/mainmenu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mainmenu()
$ani_dialog_height $ani_dialog_width $ani_dialog_menu_height \
"1" "> 更新 Ani2xcur" \
"2" "> 安装 win2xcur 核心" \
"2" "> 卸载 win2xcur 核心" \
"3" "> 卸载 win2xcur 核心" \
"4" "> 进入文件浏览器" \
"5" "> 退出 Ani2xcur" \
3>&1 1>&2 2>&3)
Expand Down Expand Up @@ -45,9 +45,9 @@ mainmenu()
2)
ani_echo "安装 wi2n2xcur 中"
if which win2xcur > /dev/null 2>&1; then
ani_pip install numpy wand win2xcur --break-system-package --upgrade --force-reinstall
ani_pip install numpy wand win2xcur --upgrade --force-reinstall
else
ani_pip install numpy wand win2xcur --break-system-package --upgrade
ani_pip install numpy wand win2xcur --upgrade
fi
if [ $? = 0 ];then
dialog --erase-on-exit \
Expand Down Expand Up @@ -81,8 +81,16 @@ mainmenu()
fi
;;
4)
cd ..
file_browser
if which win2xcur > /dev/null 2>&1 ;then
cd ..
file_browser
else
dialog --erase-on-exit \
--title "Ani2xcur" \
--backtitle "文件浏览器" \
--ok-label "确认" \
--msgbox "win2xcur 核心未安装, 请安装后重试" $ani_dialog_height $ani_dialog_width
fi
;;
*)
break
Expand Down
27 changes: 25 additions & 2 deletions modules/python_cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,34 @@
# python命令
ani_pyhton()
{
"$ani_python_path" "$@"
# 检测是否在虚拟环境中
if [ ! -z "$VIRTUAL_ENV" ];then # 当处在虚拟环境时
# 检测使用哪种命令调用python
# 调用虚拟环境的python
if [ ! -z "$(python --version 2> /dev/null)" ];then
python "$@" # 加双引号防止运行报错
elif [ ! -z "$(python3 --version 2> /dev/null)" ];then
python3 "$@"
fi
else # 不在虚拟环境时
#调 用系统中存在的python
"$ani_python_path" "$@"
fi
}

# pip命令
ani_pip()
{
ani_pyhton -m pip "$@"
# 检测是否在虚拟环境中
if [ ! -z "$VIRTUAL_ENV" ];then
# 调用虚拟环境的pip
if [ ! -z "$(python --version 2> /dev/null)" ];then
python -m pip "$@"
elif [ ! -z "$(python3 --version 2> /dev/null)" ];then
python3 -m pip "$@"
fi
else
# 调用系统中存在的pip
"$ani_python_path" -m pip "$@"
fi
}
40 changes: 24 additions & 16 deletions modules/win2xcur.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ ani_win2xcur()
local cur_list
local inf_file=$1 # 鼠标指针配置文件
local exec_time=$(date "+%Y-%m-%d-%H-%M-%S") # 执行结束时间
local inf_parent_path=$(dirname "$inf_file")

# 检测win2xcur核心是否安装
if ! which win2xcur > /dev/null 2>&1 ;then
ani_echo "win2xcur 核心未安装"
return 1
fi

# 获取配置文件
ani_echo "读取配置文件: $inf_file"
cat "$inf_file" | awk '/\[Strings\]/ { print; flag = 1; next } /=/ { if (flag == 1){ print } }' > "$start_path"/task/ani_info_origin.conf # 读取inf配置
iconv -f GBK -t UTF-8 "$start_path"/task/ani_info_origin.conf > "$start_path"/task/ani_info.conf # 编码转换
Expand Down Expand Up @@ -63,105 +71,105 @@ ani_win2xcur()
if [ -z "$cur_pointer" ];then # 不存在时从指针库复制
cp -f "$start_path"/source/left_ptr "$start_path"/task/"$exec_time"/cursors
else
cp -f "$(ls -a | grep -iw "$cur_pointer")" "$start_path"/task/cursors_tmp/left_ptr.ani # 复制鼠标指针到缓存文件夹
cp -f "$inf_parent_path/$(ls -a "$inf_parent_path" | grep -iw "$cur_pointer")" "$start_path"/task/cursors_tmp/left_ptr.ani # 复制鼠标指针到缓存文件夹
win2xcur "$start_path"/task/cursors_tmp/left_ptr.ani -o "$start_path"/task/"$exec_time"/cursors # 转换后存到鼠标指针文件夹
fi

if [ -z "$cur_help" ];then
cp -f "$start_path"/source/question_arrow "$start_path"/task/"$exec_time"/cursors
else
cp -f "$(ls -a | grep -iw "$cur_help")" "$start_path"/task/cursors_tmp/question_arrow.ani
cp -f "$inf_parent_path/$(ls -a "$inf_parent_path" | grep -iw "$cur_help")" "$start_path"/task/cursors_tmp/question_arrow.ani
win2xcur "$start_path"/task/cursors_tmp/question_arrow.ani -o "$start_path"/task/"$exec_time"/cursors
fi

if [ -z "$cur_work" ];then
cp -f "$start_path"/source/left_ptr_watch "$start_path"/task/"$exec_time"/cursors
else
cp -f "$(ls -a | grep -iw "$cur_work")" "$start_path"/task/cursors_tmp/left_ptr_watch.ani
cp -f "$inf_parent_path/$(ls -a "$inf_parent_path" | grep -iw "$cur_work")" "$start_path"/task/cursors_tmp/left_ptr_watch.ani
win2xcur "$start_path"/task/cursors_tmp/left_ptr_watch.ani -o "$start_path"/task/"$exec_time"/cursors
fi

if [ -z "$cur_busy" ];then
cp -f "$start_path"/source/wait "$start_path"/task/"$exec_time"/cursors
else
cp -f "$(ls -a | grep -iw "$cur_busy")" "$start_path"/task/cursors_tmp/wait.ani
cp -f "$inf_parent_path/$(ls -a "$inf_parent_path" | grep -iw "$cur_busy")" "$start_path"/task/cursors_tmp/wait.ani
win2xcur "$start_path"/task/cursors_tmp/wait.ani -o "$start_path"/task/"$exec_time"/cursors
fi

if [ -z "$cur_cross" ];then
cp -f "$start_path"/source/cross "$start_path"/task/"$exec_time"/cursors
else
cp -f "$(ls -a | grep -iw "$cur_cross")" "$start_path"/task/cursors_tmp/cross.ani
cp -f "$inf_parent_path/$(ls -a "$inf_parent_path" | grep -iw "$cur_cross")" "$start_path"/task/cursors_tmp/cross.ani
win2xcur "$start_path"/task/cursors_tmp/cross.ani -o "$start_path"/task/"$exec_time"/cursors
fi

if [ -z "$cur_text" ];then
cp -f "$start_path"/source/xterm "$start_path"/task/"$exec_time"/cursors
else
cp -f "$(ls -a | grep -iw "$cur_text")" "$start_path"/task/cursors_tmp/xterm.ani
cp -f "$inf_parent_path/$(ls -a "$inf_parent_path" | grep -iw "$cur_text")" "$start_path"/task/cursors_tmp/xterm.ani
win2xcur "$start_path"/task/cursors_tmp/xterm.ani -o "$start_path"/task/"$exec_time"/cursors
fi

if [ -z "$cur_hand" ];then
cp -f "$start_path"/source/pencil "$start_path"/task/"$exec_time"/cursors
else
cp -f "$(ls -a | grep -iw "$cur_hand")" "$start_path"/task/cursors_tmp/pencil.ani
cp -f "$inf_parent_path/$(ls -a "$inf_parent_path" | grep -iw "$cur_hand")" "$start_path"/task/cursors_tmp/pencil.ani
win2xcur "$start_path"/task/cursors_tmp/pencil.ani -o "$start_path"/task/"$exec_time"/cursors
fi

if [ -z "$cur_unavailiable" ];then
cp -f "$start_path"/source/circle "$start_path"/task/"$exec_time"/cursors
else
cp -f "$(ls -a | grep -iw "$cur_unavailiable")" "$start_path"/task/cursors_tmp/circle.ani
cp -f "$inf_parent_path/$(ls -a "$inf_parent_path" | grep -iw "$cur_unavailiable")" "$start_path"/task/cursors_tmp/circle.ani
win2xcur "$start_path"/task/cursors_tmp/circle.ani -o "$start_path"/task/"$exec_time"/cursors
fi

if [ -z "$cur_vert" ];then
cp -f "$start_path"/source/bottom_side "$start_path"/task/"$exec_time"/cursors
else
cp -f "$(ls -a | grep -iw "$cur_vert")" "$start_path"/task/cursors_tmp/bottom_side.ani
cp -f "$inf_parent_path/$(ls -a "$inf_parent_path" | grep -iw "$cur_vert")" "$start_path"/task/cursors_tmp/bottom_side.ani
win2xcur "$start_path"/task/cursors_tmp/bottom_side.ani -o "$start_path"/task/"$exec_time"/cursors
fi

if [ -z "$cur_horz" ];then
cp -f "$start_path"/source/left_side "$start_path"/task/"$exec_time"/cursors
else
cp -f "$(ls -a | grep -iw "$cur_horz")" "$start_path"/task/cursors_tmp/left_side.ani
cp -f "$inf_parent_path/$(ls -a "$inf_parent_path" | grep -iw "$cur_horz")" "$start_path"/task/cursors_tmp/left_side.ani
win2xcur "$start_path"/task/cursors_tmp/left_side.ani -o "$start_path"/task/"$exec_time"/cursors
fi

if [ -z "$cur_dgn1" ];then
cp -f "$start_path"/source/bottom_right_corner "$start_path"/task/"$exec_time"/cursors
else
cp -f "$(ls -a | grep -iw "$cur_dgn1")" "$start_path"/task/cursors_tmp/bottom_right_corner.ani
cp -f "$inf_parent_path/$(ls -a "$inf_parent_path" | grep -iw "$cur_dgn1")" "$start_path"/task/cursors_tmp/bottom_right_corner.ani
win2xcur "$start_path"/task/cursors_tmp/bottom_right_corner.ani -o "$start_path"/task/"$exec_time"/cursors
fi

if [ -z "$cur_dgn2" ];then
cp -f "$start_path"/source/bottom_left_corner "$start_path"/task/"$exec_time"/cursors
else
cp -f "$(ls -a | grep -iw "$cur_dgn2")" "$start_path"/task/cursors_tmp/bottom_left_corner.ani
cp -f "$inf_parent_path/$(ls -a "$inf_parent_path" | grep -iw "$cur_dgn2")" "$start_path"/task/cursors_tmp/bottom_left_corner.ani
win2xcur "$start_path"/task/cursors_tmp/bottom_left_corner.ani -o "$start_path"/task/"$exec_time"/cursors
fi

if [ -z "$cur_move" ];then
cp -f "$start_path"/source/move "$start_path"/task/"$exec_time"/cursors
else
cp -f "$(ls -a | grep -iw "$cur_move")" "$start_path"/task/cursors_tmp/move.ani
cp -f "$inf_parent_path/$(ls -a "$inf_parent_path" | grep -iw "$cur_move")" "$start_path"/task/cursors_tmp/move.ani
win2xcur "$start_path"/task/cursors_tmp/move.ani -o "$start_path"/task/"$exec_time"/cursors
fi

if [ -z "$cur_alternate" ];then
cp -f "$start_path"/source/dotbox "$start_path"/task/"$exec_time"/cursors
else
cp -f "$(ls -a | grep -iw "$cur_alternate")" "$start_path"/task/cursors_tmp/dotbox.ani
cp -f "$inf_parent_path/$(ls -a "$inf_parent_path" | grep -iw "$cur_alternate")" "$start_path"/task/cursors_tmp/dotbox.ani
win2xcur "$start_path"/task/cursors_tmp/dotbox.ani -o "$start_path"/task/"$exec_time"/cursors
fi

if [ -z "$cur_link" ];then
cp -f "$start_path"/source/hand2 "$start_path"/task/"$exec_time"/cursors
else
cp -f "$(ls -a | grep -iw "$cur_link")" "$start_path"/task/cursors_tmp/hand2.ani
cp -f "$inf_parent_path/$(ls -a "$inf_parent_path" | grep -iw "$cur_link")" "$start_path"/task/cursors_tmp/hand2.ani
win2xcur "$start_path"/task/cursors_tmp/hand2.ani -o "$start_path"/task/"$exec_time"/cursors
fi

Expand Down Expand Up @@ -361,7 +369,7 @@ ani_win2xcur()
echo "# 鼠标指针安装" > "$start_path"/output/"$exec_time"/install.sh
echo "echo \"将鼠标指针安装至 ~/.icons\"" >> "$start_path"/output/"$exec_time"/install.sh
echo "cp -r ./$cur_name ~/.icons" >> "$start_path"/output/"$exec_time"/install.sh
echo "echo \"安装完成, 可使用 \"gsettings set org.gnome.desktop.interface cursor-theme \"$cur_name\" 启用该鼠标指针\"" >> "$start_path"/output/"$exec_time"/install.sh
echo "echo \"安装完成, 可使用 \\\"gsettings set org.gnome.desktop.interface cursor-theme \\\"$cur_name\\\"\\\" 启用该鼠标指针\"" >> "$start_path"/output/"$exec_time"/install.sh

ani_echo "转换结束, 鼠标指针文件保存路径: "$start_path"/output/"$exec_time""
}

0 comments on commit 9a8c64f

Please sign in to comment.