Skip to content

Commit 9bb7cc9

Browse files
committed
更新路径解析逻辑
1 parent 254b149 commit 9bb7cc9

10 files changed

Lines changed: 72 additions & 36 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 注意:3.9.2 之后版本的开发文档,改为随示例APK发布
2+
# 在线的文档将不再同步更新
3+
# 以下内容仅适于3.9.1及以前的版本
4+
15
## 简介
26

37
### 功能用途

krscript/src/main/java/com/omarea/krscript/config/PathAnalysis.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,24 @@ class PathAnalysis(private var context: Context, private var parentDir: String =
3434
// TODO:处理 ../ 、 ./
3535
private fun pathConcat(parent: String, target: String): String {
3636
val isAssets = parent.startsWith(ASSETS_FILE)
37-
val parentDir = if (isAssets) parentDir.substring(ASSETS_FILE.length) else parent
37+
val parentDir = if (isAssets) parent.substring(ASSETS_FILE.length) else parent
38+
val parentSlices = ArrayList(parentDir.split("/"))
39+
if (target.startsWith("../") && parentSlices.size > 0) {
40+
val targetSlices = ArrayList(target.split("/"))
41+
while (true) {
42+
val step = targetSlices.firstOrNull()
43+
if (step != null && step == ".." && parentSlices.size > 0) {
44+
parentSlices.removeAt(parentSlices.size - 1)
45+
targetSlices.removeAt(0)
46+
} else {
47+
break
48+
}
49+
}
50+
return pathConcat((if (isAssets) ASSETS_FILE else "" )+ parentSlices.joinToString("/"), targetSlices.joinToString("/"))
51+
}
3852

3953
return (if (isAssets) ASSETS_FILE else "" )+ ( when {
40-
!parentDir.endsWith("/") -> parentDir + "/"
54+
!(parentDir.isEmpty() || parentDir.endsWith("/")) -> parentDir + "/"
4155
else -> parentDir
4256
} + (if (target.startsWith("./")) target.substring(2) else target))
4357
}

krscript/src/main/java/com/omarea/krscript/executor/ScriptEnvironmen.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,15 @@ public static String executeResultRoot(Context context, String script, NodeInfoB
194194
if (nodeInfoBase != null && !nodeInfoBase.getCurrentPageConfigPath().isEmpty()) {
195195
String parentPageConfigDir = nodeInfoBase.getPageConfigDir();
196196
String currentPageConfigPath = nodeInfoBase.getCurrentPageConfigPath();
197-
stringBuilder.append("export PAGE_CONFIG_DIR='" + parentPageConfigDir + "'\n");
198-
stringBuilder.append("export PAGE_CONFIG_FILE='" + currentPageConfigPath + "'\n");
197+
stringBuilder.append("export PAGE_CONFIG_DIR='").append(parentPageConfigDir).append("'\n");
198+
stringBuilder.append("export PAGE_CONFIG_FILE='").append(currentPageConfigPath).append("'\n");
199199

200200
if (currentPageConfigPath.startsWith("file:///android_asset/")) {
201-
stringBuilder.append("export PAGE_WORK_DIR='" + new ExtractAssets(context).getExtractPath(parentPageConfigDir) + "'\n");
202-
stringBuilder.append("export PAGE_WORK_FILE='" + new ExtractAssets(context).getExtractPath(currentPageConfigPath) + "'\n");
201+
stringBuilder.append("export PAGE_WORK_DIR='").append(new ExtractAssets(context).getExtractPath(parentPageConfigDir)).append("'\n");
202+
stringBuilder.append("export PAGE_WORK_FILE='").append(new ExtractAssets(context).getExtractPath(currentPageConfigPath)).append("'\n");
203203
} else {
204-
stringBuilder.append("export PAGE_WORK_DIR='" + parentPageConfigDir + "'\n");
205-
stringBuilder.append("export PAGE_WORK_FILE='" + currentPageConfigPath + "'\n");
204+
stringBuilder.append("export PAGE_WORK_DIR='").append(parentPageConfigDir).append("'\n");
205+
stringBuilder.append("export PAGE_WORK_FILE='").append(currentPageConfigPath).append("'\n");
206206
}
207207
} else {
208208
stringBuilder.append("export PAGE_CONFIG_DIR=''\n");

pio/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
resConfigs "zh"
1111
minSdkVersion 21
1212
targetSdkVersion 28
13-
versionCode 96
14-
versionName "3.9.1"
13+
versionCode 97
14+
versionName "3.9.2"
1515
}
1616
buildTypes {
1717
release {

pio/src/main/assets/docs/Page.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
| logo | 作为快捷方式添加到桌面时使用的图标 | 文件路径 | |
2828
| icon | 显示在功能左侧的图标。如果未设置logo属性,它也同时会被作为logo使用 | 文件路径 | |
2929

30-
31-
> `logo``icon`除了支持assets文件路径,也支持磁盘文件路径
30+
> 注意:仅限定义了config、config-sh的page才能成为一个有效的快捷方式!
3231
3332
- 特有属性
3433

pio/src/main/assets/docs/Script.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@
7777
| APP_USER_ID | 安卓中每个应用都有一个单独的UserID |
7878
| ROOT_PERMISSION | 是否已经获得ROOT权限,值为true/false |
7979

80+
#### 特殊(动态)变量
81+
- 这几个较为特殊的变量是在3.9.2版本中新增的
82+
- 用于定位XML配置来源路径和释放路径
83+
84+
| 参数名 | 说明 |
85+
| - | - |
86+
| PAGE_CONFIG_DIR | 页面(Page)的配置文件源目录 |
87+
| PAGE_CONFIG_FILE | 页面(Page)的配置文件源文件 |
88+
| PAGE_WORK_DIR | 页面(Page)的配置文件提取目录 |
89+
| PAGE_WORK_FILE | 页面(Page)的配置文件提取路径 |
90+
91+
> 有何作用?<br />
92+
> 两个源路径可以帮助你判断PIO是否加载正确的配置文件<br />
93+
> 而后两个`WORK`变量,则是为了尽可能减少写死的固定路径,便于逻辑脚本和配置xml一同迁移目录
94+
95+
8096
## 相关说明
8197
> 如果你在脚本里创建了目录,建议将所有者设置为 `$APP_USER_ID` <br/>
8298
> 原因和用法见 [resource](#/doc?doc=/docs/Resource.md)**警告** 部分
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<items>
33
<group title="运行环境测试">
4-
<page config="samples/env/env.xml" title="环境测试" />
4+
<page config="env/env.xml" title="环境测试">
5+
<resource dir="file:///android_asset/samples/env" />
6+
</page>
57
</group>
68

79
<group title="Action 功能测试">
8-
<page config="samples/action.xml" title="Action用法" />
10+
<page config="action.xml" title="Action用法" />
911
</group>
1012

1113
<group title="Switch 功能测试">
12-
<page config="samples/switch.xml" title="Switch用法" />
14+
<page config="switch.xml" title="Switch用法" />
1315
</group>
1416

1517
<group title="Picker 功能测试">
16-
<page config="samples/picker.xml" title="Picker用法" />
18+
<page config="picker.xml" title="Picker用法" />
1719
</group>
1820

1921
<group title="Text 功能测试">
20-
<page config="samples/text.xml" title="Text用法" />
22+
<page config="text.xml" title="Text用法" />
2123
</group>
2224

2325
<group title="Page 功能测试">
24-
<page config="samples/page.xml" title="Page用法" />
26+
<page config="page.xml" title="Page用法" />
2527
</group>
2628

2729
<group title="关联刷新测试">
28-
<page config="samples/reload.xml" title="reload 属性" />
30+
<page config="reload.xml" title="reload 属性" />
2931
</group>
3032

3133
<group title="后台任务">
32-
<page config="samples/bg_task/bg_task.xml" title="后台任务" />
34+
<page config="bg_task/bg_task.xml" title="后台任务" />
3335
</group>
3436

3537
<group title="Web引擎">
36-
<page config="samples/web.xml" title="网页引擎测试" />
38+
<page config="web.xml" title="网页引擎测试" />
3739
</group>
3840

3941
<group title="快捷方式">
40-
<page config="samples/shortcut.xml" title="快捷方式测试" />
42+
<page config="shortcut.xml" title="快捷方式测试" />
4143
</group>
4244
</items>

pio/src/main/assets/samples/env/env.xml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<page>
3-
<resource dir="file:///android_asset/samples/env" />
4-
53
<group>
64
<action>
75
<title>busybox 测试</title>
86
<desc>测试toolkit目录中放置的busybox是否生效</desc>
9-
<set>samples/env/env.sh busybox_version</set>
7+
<set>$PAGE_WORK_DIR/env.sh busybox_version</set>
108
</action>
119

1210
<action>
@@ -24,25 +22,25 @@
2422
<action confirm="true">
2523
<title>卸载系统自带的busybox</title>
2624
<desc>卸载安装到system分区的busybox</desc>
27-
<set>samples/env/env.sh busybox_uninstall</set>
25+
<set>$PAGE_WORK_DIR/env.sh busybox_uninstall</set>
2826
</action>
2927
</group>
3028

3129
<group>
3230
<action>
3331
<title>环境变量</title>
34-
<set>samples/env/env.sh environment</set>
32+
<set>$PAGE_WORK_DIR/env.sh environment</set>
3533
</action>
3634

3735
<!--<action>
3836
<title>【配置文件】路径信息</title>
3937
<desc>查看当前配置文件XML提取路径和提取目录</desc>
40-
<set>samples/env/env.sh config_path</set>
38+
<set>$PAGE_WORK_DIR/env.sh config_path</set>
4139
</action>-->
4240

4341
<action>
4442
<title>用户ID检测</title>
45-
<set>samples/env/env.sh root_state</set>
43+
<set>$PAGE_WORK_DIR/env.sh root_state</set>
4644
</action>
4745
</group>
4846
</page>

pio/src/main/assets/samples/page.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
4. 页面加载【失败】:[load-fail] / [after-error]
1313
-->
1414
<page after-read="sleep 2" before-read="sleep 5"
15-
config="samples/kt/kernel_tuner.xml">
15+
config="kt/kernel_tuner.xml">
1616
<title>page功能测试</title>
1717
<desc>来试试page的新功能</desc>
1818
</page>
@@ -50,7 +50,7 @@
5050
</group>
5151

5252
<group title="页面菜单">
53-
<page config="samples/empty.xml">
53+
<page config="empty.xml">
5454
<title>在页面右上角显示菜单</title>
5555
<option type="default" id="a" auto-off="true">自定义 1</option>
5656
<option type="default" id="b">自定义 2</option>
@@ -73,7 +73,7 @@
7373
type=fab 属性,其它属性的用法基本一致
7474
但是你不能在一个页面上定义多个悬浮按钮
7575
-->
76-
<page config="samples/empty.xml">
76+
<page config="empty.xml">
7777
<title>在页面显示悬浮按钮</title>
7878
<option type="file" style="fab">选择文件</option>
7979
<handler>
@@ -88,7 +88,7 @@
8888
</page>
8989

9090
<!--不管是右上角菜单还是悬浮按钮,选择文件时都可以限制类型-->
91-
<page config="samples/empty.xml">
91+
<page config="empty.xml">
9292
<title>选择指定类型的文件</title>
9393
<option type="file" style="fab" suffix="zip">选择文件</option>
9494
<handler>
@@ -98,7 +98,7 @@
9898
</page>
9999

100100
<!--你可以自己配置悬浮按钮图标-->
101-
<page config="samples/empty.xml">
101+
<page config="empty.xml">
102102
<title>自定义悬浮按钮的图标</title>
103103
<option style="fab" icon="samples/icons/icon-test.png">测试按钮图标</option>
104104
<handler>

pio/src/main/assets/samples/shortcut.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</script>
2323
</action>
2424

25-
<action logo="samples/icons/icon-test.png" id="shortcut_003">
25+
<action logo="icons/icon-test.png" id="shortcut_003">
2626
<title>图标定义</title>
2727
<desc>通过logo-path 或 logo 属性可以自定义快捷方式图标,最后尝试着长按这个功能,添加到桌面</desc>
2828
<script>
@@ -31,7 +31,10 @@
3131
</script>
3232
</action>
3333

34-
<page id="shortcut.xml" icon="./icons/icon-test.png" config="samples/action.xml" title="page快捷方式">
34+
<page id="shortcut.xml"
35+
icon="icons/icon-test.png"
36+
config="action.xml"
37+
title="page快捷方式">
3538
<desc>理论上,page、action、picker、switch都支持快捷方式功能</desc>
3639
</page>
3740
</group>

0 commit comments

Comments
 (0)