Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.lua
More file actions
Latest commit
73 lines (64 loc) · 2.01 KB
/
Copy pathhelper.lua
File metadata and controls
73 lines (64 loc) · 2.01 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
sdcardPath=Environment.getExternalStorageDirectory().getPath()--SD卡的目录
--- 相对路径转绝对路径
---@parampathstring 要转换的相对路径
---@paramlocalPathstring 相对的目录
functionrel2AbsPath(path, localPath)
ifpath:sub(1, 1) =="/" then
returnpath
elseiflocalPath:sub(#localPath, #localPath) =="/"
returnlocalPath..path
else
returnlocalPath.."/" ..path
end
end
---缩短路径,绝对路径转换为相对路径,如果该路径不能转换为相对路径,则原封不动返回该路径
---@parampathstring 要转换的路径
---@parambasePathstring 当前文件夹
functionshortPath(path,basePath)
--过滤末尾的/
ifbasePath:sub(#basePath,#basePath)=="/" then
basePath=basePath:sub(1,#basePath-1)
end
ifbasePathandpath:sub(1,#basePath)==basePaththen
returnstring.sub(path,string.len(basePath)+2)
else
returnpath
end
end
---路径转换成文档uri
---@parampath 路径
functionpath2DocumentUri(path)
ifString(path).startsWith(sdcardPath) then
localrelativePath=string.sub(path,string.len(sdcardPath)+2):gsub("/","%%2f")
returnUri.parse("content://com.android.externalstorage.documents/document/primary:"..relativePath)
end
end
functiongetFileNameWithoutExtensionName(path)
localname=File(path).getName()
returnname:match("(.+)%.") orname
end
functionbuildEnvPath(runDirPath)
ifrunDirPaththen
localenvPath=runDirPath.."/?.lua;"
..runDirPath.."/?/init.lua;"
..runDirPath.."/lua/?.lua;"
..runDirPath.."/lua/?/init.lua;"
envPath=envPathandenvPath..envPath:gsub("%.lua;",".aly;")
returnenvPath
end
end
functiontoast(text)
Toast.makeText(activity, text,Toast.LENGTH_SHORT).show()
end
functionreadFile(path)
localfile=io.open(path)
localcontent=file:read("*a")
file:close()
returncontent
end
functiondecodeTemplateCode(templateCode)
localcontent=templateCode:gsub("{{(.-)}}",function(key)
returnassert(loadstring("return "..key))()
end)
returncontent
end