缓存转移の自定义适配应用教程

脚本介绍

首先,脚本头部写了很多的自定义函数,有:

  • yule "text":=echo -e " text"。在输出的文本前面加了个空格,方便阅读。

  • yulen "text":=echo -en " text"

  • sepa:=echo "-------------------------------"

  • blank n:=necho ""。输出n个空白行,缺省值为1

  • jsonread [路径/文件名.json] [关键词]:简单的.json读取器

    • 示例 1

      • /data/1.json

        1
        {"name":"Nekogram","type":"1","suf":"all","dir":"/storage/emulated/0/Android/data/tw.nekomimi.nekogram/files/Telegram/","del":"no","data":"2024-09-28 06:29:11"}
      • 输入

        1
        jsonread /data/1.json del
      • 输出

        1
        no
  • dlog text:输出普通日志。格式为[日期时间] 操作: [text]

  • errlog text:输出错误日志。格式为[日期时间] 错误: [text]

  • finlog text:输出完成日志。格式为[日期时间] 完成: [text]

  • main:定义各个应用的

    • name(应用名)
    • dir(路径)
    • type(1 表示目录用文件夹进行了分类,此时下面的suf不生效;0 表示文件夹内就是要移动的文件)
    • suf(要搜寻的文件后缀名,type 为 1 时不生效,使用 | 分割,all 表示所有文件)
  • main3:面向某个类型或者应用要进行的操作

以方便你修改。自己适配应用需要修改的有:main main3 menu 和底部的脚本介绍


修改main

现有的main内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
main() {
# 定义哔哩哔哩的信息
if [[ $menu == "1" ]]; then
name="哔哩哔哩"
dir="/storage/emulated/0/Android/data/tv.danmaku.bili/download/"
type="1" # 哔哩哔哩对视频做了文件夹区分
suf=".m4s|.json"
# 定义微信的信息
elif [[ $menu == "2" ]]; then
name="微信"
dir="/data/data/com.tencent.mm/MicroMsg/"
type="1" # 微信对账号做了文件夹区分
suf="wechat file"
# 定义QQ的信息
elif [[ $menu == "3" ]]; then
name="QQ"
dir="/storage/emulated/0/Android/data/com.tencent.mobileqq/Tencent/QQfile_recv/"
type="0" # 排除子文件夹
suf="all"
# 定义Nekogram的信息
elif [[ $menu == "4" ]]; then
name="Nekogram"
dir="/storage/emulated/0/Android/data/tw.nekomimi.nekogram/files/Telegram/"
type="1"
suf="all"
# 此处插入自定义应用代码
fi
main2
}

你应该在fi的上一行开始,按格式定义应用的:

  • name(应用名)
  • dir(路径)
  • type(1 表示目录用文件夹进行了分类,此时下面的suf不生效;0 表示文件夹内就是要移动的文件)
  • suf(要搜寻的文件后缀名,type 为 1 时不生效,使用 | 分割,all 表示所有文件)

修改main3

现有的main3内容如下:

1
2
3
4
5
6
7
8
9
10
main3() {
......
......
# 此处插入自定义应用代码
# 生成本次配置的 json
touch ${output}/last.json
echo "{\"name\":\"$name\",\"type\":\"$type\",\"suf\":\"$suf\",\"dir\":\"$dir\",\"del\":\"$delete\",\"data\":\"$(date +"%Y-%m-%d %H:%M:%S")\"}" > ${output}/last.json
rm -f ${output}/error
exit 0
}

一般情况下,你应在touch ${output}/last.json前添加你要执行的操作,比如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 面向 type 1 | suf all 进行的操作
elif [[ $type == "1" && $suf == "all" ]]; then
sepa
yule "${CY}- 复制文件...${RES}"
yulen "· 创建./$name/"
mkdir "${output}/$name" 2>/dev/null
yule "${GR} [完成]${RES}"
yulen "· 移动文件到./$name/"
cp -r ${dir}* ${output}/${name} 2>/${output}/error
err=$?
yule "${GR} [完成]${RES}"
# 复制成功
if [[ $err == "0" ]]; then
yule "${GR}· 复制完成${RES}"
sepa
if [[ $delete == "yes" ]]; then
rm -rf $dir/*
yule "${GR}删除源文件成功${RES}"
fi
finlog "[$name]转移成功"
yule "${GR}已完成转移${RES}"
yule "路径${output}/$name"
# 复制失败,输出日志
else
blank
sepa
blank 2
errtext=$(cat ${output}/error)
yule "ERR: $errtext"
errlog "[$name]复制文件失败: $errtext"
blank 2
yule "${RE}· 复制出错,请检查:${RES}"
yule " 1.存储空间是否足够"
yule " 2.是否未下载文件"
yule " 3.软件是否为旧版"
yule " 4.是否未授权Root"
exit 1
fi

修改介绍选择开始菜单

介绍

现有的介绍位于脚本的525行(v1.0),内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 介绍
clear
blank 2
yule "${YE}本脚本可以将应用所下载的文件转移到你设定的目录${RES}"
blank
yule "${BL}已支持应用:${RES}"
yule "- 哔哩哔哩"
yule "- 微信"
yule "- QQ"
yule "- Nekogram"
# 这里添加新的应用
blank
sepa
yulen "${GR}开始[1]${RES}"
yulen "${RE} 退出[2]${RES}"
yule "${CY} 配置路径[3]${RES}"
yule "${BL} 我要学习自己适配应用[4]${RES}"
# 这里添加新的序号

一般情况下,你只要在上面代码加上新的应用名和序号即可,详见上方注释。

选择开始菜单

现有的选择开始菜单位于脚本的542行(v1.0),内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 选择开始菜单
for err_num in {10..0}; do
sepa
yulen "请输入[1]/[2]/[3]/[4]:"
read menu_1
case $menu_1 in
1)
# 开始
clear
blank 2
menu
exit 0
;;
2)
# 退出
blank
yule "${GR}脚本已退出,欢迎下次使用${RES}"
exit 0
;;
3)
# 配置路径
clear
blank 2
yulen "功能研发中,请编辑脚本顶部的 output= 进行配置"
exit 0
;;
4)
# 使用浏览器打开教程
am start -a android.intent.action.VIEW -d "https://baidu.com/"
exit 0
;;
n)
......
;;
*|\n)
# 输入错误
jam $err_num $menu_1
;;


esac
done

blank
yule "${RE}你已连续输入错误10次,被系统判定为卡死,已退出脚本"

这里被介绍

1
2
3
4
yulen "${GR}开始[1]${RES}"
yulen "${RE} 退出[2]${RES}"
yule "${CY} 配置路径[3]${RES}"
yule "${BL} 我要学习自己适配应用[4]${RES}"

所选择,只要在*|\n)的上一行添加

1
2
3
[序号])
[操作]
;;

就可以了。


相关内容

缓存转移开源 | YuleのBlog - Post 12

缓存转移下载 | 123云盘