Skip to content
This repository has been archived by the owner on Oct 28, 2023. It is now read-only.

Commit

Permalink
Misc improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
a1ive committed Jan 23, 2017
1 parent 99a6e59 commit 486fef7
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 329 deletions.
90 changes: 27 additions & 63 deletions boot/grub/fm/FileList.cfg
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
#显示文件列表
#--根据变量$list_dir目录列出所有子项菜单
#--选择子项时,判断是目录/文件。
#----目录:设置$list_dir变量,显示新子项菜单。
#----文件:弹出操作菜单
#变量:
#--$list_dir_this 本层菜单地址
#--$list_dir 公用,传递参数
#--$wildcard 使用的通配符,为了避免枚举盘符避免冲突
# Grub2-FileManager
# Copyright (C) 2016,2017 A1ive.
#
# Grub2-FileManager is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Grub2-FileManager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Grub2-FileManager. If not, see <http://www.gnu.org/licenses/>.

source ${prefix}/fm/Type.cfg;

insmod regexp;
insmod probe;
source "${prefix}/fm/Tools.cfg";
set file_list_src="${prefix}/fm/FileList.cfg";
set file_op_src="${prefix}/fm/FileOP.cfg";

#为了避免太长if结构,封装为函数
function funcListFile {
#检测参数合法并设置通配符变量$wildcard
if test -z "${list_dir}"; then
#参数空则从盘符开始枚举
set list_dir="";
set wildcard="(*)";
elif test -e "${list_dir}"; then
#盘符(hd0,1)合法,(hd0)不合法
set wildcard="/*";
else
echo;
echo;
funcErrorNoFindOrCanNotRead "${list_dir}";
echo "错误! 无法读取 [${list_dir}] !";
echo -n "按[ESC]继续...";
sleep --interruptible 999;
return 1;
fi;
#保存本层目录地址并设置list_dir可传递
export list_dir;
set list_dir_this="${list_dir}";

if ! regexp '^$' "${list_dir_this}"; then
#生成当前目录项,防止空目录自动跳回
menuentry "返回上一级" --class go-previous{
set list_dir="";
regexp --set=list_dir '(^.*)/.*$' "${list_dir_this}";
Expand All @@ -45,27 +44,19 @@ function funcListFile {
configfile ${prefix}/fm/FileList.cfg;
}
fi
#枚举子项
for obj in "${list_dir_this}"${wildcard}; do
#去掉路径中的“msdos”
funcRemoveCharMSDOS "${obj}";
set obj="$str";
unset str;
#检查目录/文件
if test -d "${obj}"; then
#目录
set icon="dir";
if regexp '^\([c][d].*+\)$' "${obj}"; then
set icon="iso";
elif regexp '^\([h][d].*+\)$' "${obj}"; then
set icon="hdd";
fi
if regexp '^\(proc\)$' "${obj}"; then
echo "忽略/proc目录";
echo "ignore proc";
elif regexp '^\(memdisk\)$' "${obj}"; then
echo "忽略memdisk";
echo "ignore memdisk";
elif regexp '^$' "${list_dir_this}"; then
#根目录
probe --set=devlbl -l $obj;
probe --set=devfs -f $obj;
menuentry "${obj} [$devfs] $devlbl" "${obj}" --class ${icon}{
Expand All @@ -81,31 +72,7 @@ function funcListFile {
}
fi
elif test -f "${obj}"; then
#文件
set icon="txt"
funcGetFileExtName "${obj}";
if regexp '^[iI][sS][oO]$' "${str}"; then
set icon="iso";
elif regexp '^[zZ][iI][pP]$' "${str}"; then
set icon="7z";
elif regexp '^[xXgGlL7][zZ]$' "${str}"; then
set icon="7z";
elif regexp '^[wW][iI][mM]$' "${str}"; then
set icon="wim";
elif regexp '^[pP][nN][gG]$' "${str}"; then
set icon="png";
elif regexp '^[jJ][pP][gG]$' "${str}"; then
set icon="png";
elif regexp '^[bB][mM][pP]$' "${str}"; then
set icon="png";
elif regexp '^[lL][uU][aA]$' "${str}"; then
set icon="lua";
elif regexp '^[eE][fF][iI]$' "${str}"; then
set icon="uefi";
elif regexp '^[eE][xX][eE]$' "${str}"; then
set icon="exe"
fi
unset str;
funcGetFileType "${obj}";
menuentry "${obj}" "${obj}" --class ${icon} --class os{
set list_dir="$2";
configfile "${file_op_src}";
Expand All @@ -115,33 +82,31 @@ function funcListFile {
fi;
done;
if regexp '^$' "${list_dir_this}"; then
#根目录
funcBootDisk;
hiddenentry "分辨率设置: $gfxmode" --class settings --hotkey=r{
configfile ${prefix}/fm/GFXMode.cfg
}
menuentry "重启计算机" --class reboot{
reboot;
}
menuentry "关闭计算机" --class halt{
halt;
}
fi
#清理环境
unset obj;
unset wildcard;
echo "done!";
}

function funcBootDisk{
for dev in (*); do
#是否可读
test -e ${dev};
if test "$?" = "1"; then
continue;
fi;
#去除括号
regexp --set=device '\((.*)\)' $dev;
#枚举
if test -f ($device)/efi/microsoft/boot/bootmgfw.efi -a -f ($device)/efi/microsoft/boot/bcd; then
menuentry "启动 Windows 操作系统 位于 $device" $device --class wim{
menuentry "启动位于${device}的 Windows 操作系统 " $device --class wim{
set root=$2
chainloader ($root)/efi/microsoft/boot/bootmgfw.efi;
boot;
Expand All @@ -151,5 +116,4 @@ function funcBootDisk{
done;
}

#调用主体函数
funcListFile;
70 changes: 37 additions & 33 deletions boot/grub/fm/FileOP.cfg
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
insmod regexp;
source ${prefix}/fm/Tools.cfg;
# Grub2-FileManager
# Copyright (C) 2016,2017 A1ive.
#
# Grub2-FileManager is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Grub2-FileManager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Grub2-FileManager. If not, see <http://www.gnu.org/licenses/>.

source ${prefix}/fm/Type.cfg;
source "${prefix}/fm/LinuxISOBoot.cfg";
#文件操作菜单

#挂载为光盘
function funcAddCD {
set added_menu="${added_menu} funcAddCD";
echo "挂载 ${list_dir}";
loopback loop "${list_dir}";
menuentry "查看ISO内容" --class iso{
set list_dir="(loop)";
Expand All @@ -15,40 +27,45 @@ function funcAddCD {
}
funcCheckType;
if test -f (loop)/efi/boot/bootx64.efi; then
menuentry "启动 bootx64.efi" --class iso{
menuentry "启动 bootx64.efi" --class iso{
chainloader (loop)/efi/boot/bootx64.efi;
}
fi
}
#当作[Grub2菜单文件]载入

function funcAddCFG {
set added_menu="${added_menu} funcAddCFG";
menuentry "作为Grub2菜单文件载入" --class cfg{
funcGetDevName "${list_dir}";
regexp --set=str '^\(([0-9a-zA-Z,]+)\).*$' "${list_dir}"
set root="${str}";
configfile "${list_dir}";
}
menuentry "作为Syslinux菜单文件载入" --class cfg{
regexp --set=str '^\(([0-9a-zA-Z,]+)\).*$' "${list_dir}"
set root="${str}";
syslinuxcfg "${list_dir}";
}
}
#当作[Lua脚本]运行

function funcAddLUA {
set added_menu="${added_menu} funcAddLUA";
menuentry "作为Lua脚本运行" --class lua{
funcGetDevName "${list_dir}";
regexp --set=str '^\(([0-9a-zA-Z,]+)\).*$' "${list_dir}"
set root="${str}";
lua "${list_dir}";
echo -n "按 [ESC] 键返回...";
sleep --interruptible 999;
}
}
#当作[EFI文件]运行

function funcAddEFI {
set added_menu="${added_menu} funcAddEFI";
menuentry "作为EFI可执行文件运行" --class uefi{
chainloader ${list_dir};
boot;
}
}
#显示图片

function funcAddPNG {
set added_menu="${added_menu} funcAddPNG";
submenu "查看图片 (PNG)" --class png{
Expand All @@ -58,7 +75,7 @@ function funcAddPNG {
background_image ${prefix}/themes/slack/black.png
}
}
#适用于所有文件的操作

function funcAddAll {
set added_menu="${added_menu} funcAddAll";
menuentry "显示文本内容" --class txt{
Expand All @@ -80,10 +97,6 @@ function funcAddAll {
}
}

#检查文件格式
funcGetFileExtName "${list_dir}";


menuentry "返回" --class go-previous{
regexp --set=list_dir '(.*)\/.*$' "${list_dir}";
unset devnum;
Expand All @@ -93,29 +106,20 @@ menuentry "返回" --class go-previous{
configfile ${prefix}/fm/FileList.cfg;
}

if regexp '^[iI][sS][oO]$' "${str}"; then
#iso
funcAddCD;
elif regexp '^[cC][fF][gG]$' "${str}"; then
#cfg
funcGetFileType "${list_dir}";
if regexp 'cfg' "$type"; then
funcAddCFG;
elif regexp '^[lL][uU][aA]$' "${str}"; then
#lua
elif regexp 'lua' "$type"; then
funcAddLUA;
elif regexp '^[eE][fF][iI]$' "${str}"; then
#efi
elif regexp 'efi' "$type"; then
funcAddEFI;
elif regexp '^[pP][nN][gG]$' "${str}"; then
#png
funcAddPNG;
elif regexp '^[jJ][pP][gG]$' "${str}"; then
#jpg
elif regexp 'image' "$type"; then
funcAddPNG;
elif regexp 'iso' "$type"; then
funcAddCD;
fi

funcAddAll;

#清理环境
unset devnum;
unset str;
unset sequence;
Expand Down
67 changes: 67 additions & 0 deletions boot/grub/fm/GFXMode.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Grub2-FileManager
# Copyright (C) 2016,2017 A1ive.
#
# Grub2-FileManager is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Grub2-FileManager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Grub2-FileManager. If not, see <http://www.gnu.org/licenses/>.

terminal_output console
menuentry "[0] AUTO DETECT" --hotkey=0{
set gfxmode=auto
terminal_output gfxterm
configfile ${prefix}/fm/FileList.cfg
}
menuentry "[1] 640x480" --hotkey=1{
set gfxmode=640x480
terminal_output gfxterm
configfile ${prefix}/fm/FileList.cfg
}
menuentry "[2] 800x600" --hotkey=2{
set gfxmode=800x600
terminal_output gfxterm
configfile ${prefix}/fm/FileList.cfg
}
menuentry "[3] 1024x768" --hotkey=3{
set gfxmode=1024x768
terminal_output gfxterm
configfile ${prefix}/fm/FileList.cfg
}
menuentry "[4] 1280x1024" --hotkey=4{
set gfxmode=1280x1024
terminal_output gfxterm
configfile ${prefix}/fm/FileList.cfg
}
menuentry "[5] 1366x768" --hotkey=5{
set gfxmode=1366x768
terminal_output gfxterm
configfile ${prefix}/fm/FileList.cfg
}
menuentry "[6] 1600x1200" --hotkey=6{
set gfxmode=1600x1200
terminal_output gfxterm
configfile ${prefix}/fm/FileList.cfg
}
menuentry "[7] 1920x1080" --hotkey=7{
set gfxmode=1920x1080
terminal_output gfxterm
configfile ${prefix}/fm/FileList.cfg
}
menuentry "[8] 1920x1440" --hotkey=8{
set gfxmode=1920x1440
terminal_output gfxterm
configfile ${prefix}/fm/FileList.cfg
}
menuentry "[9] 2160x1440" --hotkey=9{
set gfxmode=2160x1440
terminal_output gfxterm
configfile ${prefix}/fm/FileList.cfg
}
Loading

0 comments on commit 486fef7

Please sign in to comment.