Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
DoraemonKit
提交
869e22ea
D
DoraemonKit
项目概览
DiDi
/
DoraemonKit
10 个月 前同步成功
通知
166
Star
19623
Fork
3062
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
DoraemonKit
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
869e22ea
编写于
6月 29, 2020
作者:
J
jackjintai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
android:新增相对路径
上级
719a7993
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
174 addition
and
101 deletion
+174
-101
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/DokitFileRouter.kt
...idichuxing/doraemonkit/kit/filemanager/DokitFileRouter.kt
+21
-23
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/FileManagerUtil.kt
...idichuxing/doraemonkit/kit/filemanager/FileManagerUtil.kt
+53
-0
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/action/file/DeleteFileAction.kt
...raemonkit/kit/filemanager/action/file/DeleteFileAction.kt
+1
-1
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/action/file/DeviceInfoAction.kt
...raemonkit/kit/filemanager/action/file/DeviceInfoAction.kt
+1
-1
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/action/file/FileDetailAction.kt
...raemonkit/kit/filemanager/action/file/FileDetailAction.kt
+1
-1
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/action/file/FileListAction.kt
...doraemonkit/kit/filemanager/action/file/FileListAction.kt
+10
-7
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/action/file/IndexAction.kt
...ng/doraemonkit/kit/filemanager/action/file/IndexAction.kt
+1
-1
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/action/file/RenameFileAction.kt
...raemonkit/kit/filemanager/action/file/RenameFileAction.kt
+1
-1
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/action/file/SaveFileAction.kt
...doraemonkit/kit/filemanager/action/file/SaveFileAction.kt
+1
-1
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/action/file/UploadFileAction.kt
...raemonkit/kit/filemanager/action/file/UploadFileAction.kt
+2
-1
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/bean/DirInfo.kt
...m/didichuxing/doraemonkit/kit/filemanager/bean/DirInfo.kt
+1
-1
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/bean/RenameFileInfo.kt
...huxing/doraemonkit/kit/filemanager/bean/RenameFileInfo.kt
+1
-1
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/bean/SaveFileInfo.kt
...ichuxing/doraemonkit/kit/filemanager/bean/SaveFileInfo.kt
+1
-1
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/sqlite/DBManager.kt
...dichuxing/doraemonkit/kit/filemanager/sqlite/DBManager.kt
+79
-61
未找到文件。
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/DokitFileRouter.kt
浏览文件 @
869e22ea
...
...
@@ -72,14 +72,14 @@ val DoKitFileRouter: Application.() -> Unit = {
* index
*/
get
(
"/"
)
{
call
.
respond
(
IndexAction
.
createIndexInfo
())
call
.
respond
(
IndexAction
.
indexInfoRes
())
}
/**
* 获取设备详情
*/
get
(
"/getDeviceInfo"
)
{
call
.
respond
(
DeviceInfoAction
.
createDeviceInfo
())
call
.
respond
(
DeviceInfoAction
.
deviceInfoRes
())
}
/**
...
...
@@ -87,11 +87,11 @@ val DoKitFileRouter: Application.() -> Unit = {
*/
get
(
"/getFileList"
)
{
val
queryParameters
=
call
.
request
.
queryParameters
val
filePath
=
queryParameters
[
"filePath"
]
if
(
filePath
.
isNullOr
Blank
())
{
call
.
respond
(
RequestErrorAction
.
createErrorInfo
(
"
file
Path is not standard"
))
val
dirPath
=
FileManagerUtil
.
absoluteRootPath
(
queryParameters
[
"dirPath"
])
if
(
dirPath
.
is
Blank
())
{
call
.
respond
(
RequestErrorAction
.
createErrorInfo
(
"
dir
Path is not standard"
))
}
else
{
call
.
respond
(
FileListAction
.
createFileList
(
file
Path
))
call
.
respond
(
FileListAction
.
fileListRes
(
dir
Path
))
}
}
...
...
@@ -100,10 +100,10 @@ val DoKitFileRouter: Application.() -> Unit = {
*/
get
(
"/getFileDetail"
)
{
val
queryParameters
=
call
.
request
.
queryParameters
val
dirPath
=
queryParameters
[
"filePath"
]
val
dirPath
=
FileManagerUtil
.
absoluteRootPath
(
queryParameters
[
"dirPath"
])
val
fileType
=
queryParameters
[
"fileType"
]
val
fileName
=
queryParameters
[
"fileName"
]
call
.
respond
(
FileDetailAction
.
createFileDetailInfo
(
"$dirPath${File.separator}$fileName"
,
fileType
))
call
.
respond
(
FileDetailAction
.
fileDetailInfoRes
(
"$dirPath${File.separator}$fileName"
,
fileType
))
}
/**
...
...
@@ -111,7 +111,7 @@ val DoKitFileRouter: Application.() -> Unit = {
*/
post
(
"/createFolder"
)
{
val
params
=
call
.
receive
<
DirInfo
>()
val
dirPath
=
params
.
filePath
val
dirPath
=
FileManagerUtil
.
absoluteRootPath
(
params
.
dirPath
)
val
fileName
=
params
.
fileName
call
.
respond
(
CreateFolderAction
.
createFolderRes
(
dirPath
,
fileName
))
}
...
...
@@ -122,7 +122,6 @@ val DoKitFileRouter: Application.() -> Unit = {
post
(
"/uploadFile"
)
{
val
multipart
=
call
.
receiveMultipart
()
call
.
respond
(
UploadFileAction
.
uploadFileRes
(
multipart
))
}
/**
...
...
@@ -130,7 +129,7 @@ val DoKitFileRouter: Application.() -> Unit = {
*/
get
(
"/downloadFile"
)
{
val
queryParameters
=
call
.
request
.
queryParameters
val
dirPath
=
queryParameters
[
"filePath"
]
val
dirPath
=
FileManagerUtil
.
absoluteRootPath
(
queryParameters
[
"dirPath"
])
val
fileName
=
queryParameters
[
"fileName"
]
val
file
=
File
(
"$dirPath${File.separator}$fileName"
)
...
...
@@ -151,10 +150,10 @@ val DoKitFileRouter: Application.() -> Unit = {
*/
post
(
"/deleteFile"
)
{
val
params
=
call
.
receive
<
DirInfo
>()
val
dirPath
=
params
.
filePath
val
dirPath
=
FileManagerUtil
.
absoluteRootPath
(
params
.
dirPath
)
val
fileName
=
params
.
fileName
val
filePath
=
"$dirPath${File.separator}$fileName"
call
.
respond
(
DeleteFileAction
.
createDelet
eRes
(
filePath
,
dirPath
,
fileName
))
call
.
respond
(
DeleteFileAction
.
deleteFil
eRes
(
filePath
,
dirPath
,
fileName
))
}
/**
...
...
@@ -162,10 +161,10 @@ val DoKitFileRouter: Application.() -> Unit = {
*/
post
(
"/rename"
)
{
val
fileInfo
=
call
.
receive
<
RenameFileInfo
>()
val
dirPath
=
fileInfo
.
filePath
val
dirPath
=
FileManagerUtil
.
absoluteRootPath
(
fileInfo
.
dirPath
)
val
oldName
=
fileInfo
.
oldName
val
filePath
=
"$dirPath${File.separator}$oldName"
call
.
respond
(
RenameFileAction
.
renameRes
(
fileInfo
.
newName
,
filePath
))
call
.
respond
(
RenameFileAction
.
rename
File
Res
(
fileInfo
.
newName
,
filePath
))
}
...
...
@@ -174,11 +173,11 @@ val DoKitFileRouter: Application.() -> Unit = {
*/
post
(
"/saveFile"
)
{
val
saveFileInfo
=
call
.
receive
<
SaveFileInfo
>()
val
dirPath
=
saveFileInfo
.
filePath
val
dirPath
=
FileManagerUtil
.
absoluteRootPath
(
saveFileInfo
.
dirPath
)
val
fileName
=
saveFileInfo
.
fileName
val
content
=
saveFileInfo
.
content
val
filePath
=
"$dirPath${File.separator}$fileName"
call
.
respond
(
SaveFileAction
.
saveRes
(
content
,
filePath
))
call
.
respond
(
SaveFileAction
.
save
File
Res
(
content
,
filePath
))
}
/**
...
...
@@ -187,9 +186,8 @@ val DoKitFileRouter: Application.() -> Unit = {
get
(
"/getAllTable"
)
{
val
queryParameters
=
call
.
request
.
queryParameters
val
dirPath
=
queryParameters
[
"dirPath"
]
val
dirPath
=
FileManagerUtil
.
absoluteRootPath
(
queryParameters
[
"dirPath"
])
val
fileName
=
queryParameters
[
"fileName"
]
val
fileType
=
queryParameters
[
"fileType"
]
val
filePath
=
"$dirPath${File.separator}$fileName"
call
.
respond
(
DatabaseAction
.
allTablesRes
(
filePath
))
}
...
...
@@ -199,7 +197,7 @@ val DoKitFileRouter: Application.() -> Unit = {
*/
get
(
"/getTableData"
)
{
val
queryParameters
=
call
.
request
.
queryParameters
val
dirPath
=
queryParameters
[
"dirPath"
]
val
dirPath
=
FileManagerUtil
.
absoluteRootPath
(
queryParameters
[
"dirPath"
])
val
fileName
=
queryParameters
[
"fileName"
]
val
tableName
=
queryParameters
[
"tableName"
]
val
filePath
=
"$dirPath${File.separator}$fileName"
...
...
@@ -211,7 +209,7 @@ val DoKitFileRouter: Application.() -> Unit = {
*/
post
(
"/insertRow"
)
{
val
rowRequestInfo
=
call
.
receive
<
RowRequestInfo
>()
val
dirPath
=
rowRequestInfo
.
dirPath
val
dirPath
=
FileManagerUtil
.
absoluteRootPath
(
rowRequestInfo
.
dirPath
)
val
fileName
=
rowRequestInfo
.
fileName
val
tableName
=
rowRequestInfo
.
tableName
val
filePath
=
"$dirPath${File.separator}$fileName"
...
...
@@ -224,7 +222,7 @@ val DoKitFileRouter: Application.() -> Unit = {
*/
post
(
"/updateRow"
)
{
val
rowRequestInfo
=
call
.
receive
<
RowRequestInfo
>()
val
dirPath
=
rowRequestInfo
.
dirPath
val
dirPath
=
FileManagerUtil
.
absoluteRootPath
(
rowRequestInfo
.
dirPath
)
val
fileName
=
rowRequestInfo
.
fileName
val
tableName
=
rowRequestInfo
.
tableName
val
filePath
=
"$dirPath${File.separator}$fileName"
...
...
@@ -237,7 +235,7 @@ val DoKitFileRouter: Application.() -> Unit = {
*/
post
(
"/deleteRow"
)
{
val
rowRequestInfo
=
call
.
receive
<
RowRequestInfo
>()
val
dirPath
=
rowRequestInfo
.
dirPath
val
dirPath
=
FileManagerUtil
.
absoluteRootPath
(
rowRequestInfo
.
dirPath
)
val
fileName
=
rowRequestInfo
.
fileName
val
tableName
=
rowRequestInfo
.
tableName
val
filePath
=
"$dirPath${File.separator}$fileName"
...
...
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/FileManagerUtil.kt
0 → 100644
浏览文件 @
869e22ea
package
com.didichuxing.doraemonkit.kit.filemanager
import
com.blankj.utilcode.util.FileUtils
import
com.blankj.utilcode.util.PathUtils
/**
* ================================================
* 作 者:jint(金台)
* 版 本:1.0
* 创建日期:2020/6/29-17:10
* 描 述:
* 修订历史:
* ================================================
*/
object
FileManagerUtil
{
private
val
internalAppRootPath
by
lazy
{
PathUtils
.
getInternalAppDataPath
()
}
private
val
internalAppRootReplacePath
by
lazy
{
FileUtils
.
getFileName
(
PathUtils
.
getInternalAppDataPath
())
}
private
val
externalStorageRootPath
by
lazy
{
PathUtils
.
getExternalStoragePath
()
}
private
val
externalStorageRootReplacePath
by
lazy
{
"external"
}
/**
* 输出相对路径
*/
fun
relativeRootPath
(
path
:
String
?):
String
{
path
?.
let
{
if
(
it
.
contains
(
internalAppRootPath
))
{
return
it
.
replace
(
internalAppRootPath
,
internalAppRootReplacePath
)
}
else
if
(
it
.
contains
(
externalStorageRootPath
))
{
return
it
.
replace
(
externalStorageRootPath
,
externalStorageRootReplacePath
)
}
return
it
}
return
""
}
/**
* 合并绝对路径
*/
fun
absoluteRootPath
(
path
:
String
?):
String
{
path
?.
let
{
if
(
it
.
contains
(
internalAppRootReplacePath
))
{
return
it
.
replace
(
internalAppRootReplacePath
,
internalAppRootPath
)
}
else
if
(
it
.
contains
(
externalStorageRootReplacePath
))
{
return
it
.
replace
(
externalStorageRootReplacePath
,
externalStorageRootPath
)
}
return
it
}
return
""
}
}
\ No newline at end of file
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/action/file/DeleteFileAction.kt
浏览文件 @
869e22ea
...
...
@@ -13,7 +13,7 @@ import java.io.File
* ================================================
*/
object
DeleteFileAction
{
fun
createDelet
eRes
(
filePath
:
String
,
dirPath
:
String
,
fileName
:
String
):
MutableMap
<
String
,
Any
>
{
fun
deleteFil
eRes
(
filePath
:
String
,
dirPath
:
String
,
fileName
:
String
):
MutableMap
<
String
,
Any
>
{
val
response
=
mutableMapOf
<
String
,
Any
>()
//删除文件夹
if
(
FileUtils
.
isFileExists
(
filePath
))
{
...
...
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/action/file/DeviceInfoAction.kt
浏览文件 @
869e22ea
...
...
@@ -12,7 +12,7 @@ import com.blankj.utilcode.util.DeviceUtils
* ================================================
*/
object
DeviceInfoAction
{
fun
createDeviceInfo
():
MutableMap
<
String
,
Any
>
{
fun
deviceInfoRes
():
MutableMap
<
String
,
Any
>
{
return
mutableMapOf
<
String
,
Any
>().
apply
{
this
[
"code"
]
=
200
val
data
=
mutableMapOf
<
String
,
String
>().
apply
{
...
...
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/action/file/FileDetailAction.kt
浏览文件 @
869e22ea
...
...
@@ -13,7 +13,7 @@ import com.blankj.utilcode.util.FileUtils
* ================================================
*/
object
FileDetailAction
{
fun
createFileDetailInfo
(
filePath
:
String
,
fileType
:
String
?):
MutableMap
<
String
,
Any
>
{
fun
fileDetailInfoRes
(
filePath
:
String
,
fileType
:
String
?):
MutableMap
<
String
,
Any
>
{
val
params
=
mutableMapOf
<
String
,
Any
>()
if
(
FileUtils
.
isFileExists
(
filePath
))
{
params
[
"code"
]
=
200
...
...
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/action/file/FileListAction.kt
浏览文件 @
869e22ea
...
...
@@ -2,6 +2,7 @@ package com.didichuxing.doraemonkit.kit.filemanager.action.file
import
com.blankj.utilcode.util.FileUtils
import
com.blankj.utilcode.util.PathUtils
import
com.didichuxing.doraemonkit.kit.filemanager.FileManagerUtil
import
java.io.File
/**
...
...
@@ -14,21 +15,21 @@ import java.io.File
* ================================================
*/
object
FileListAction
{
fun
createFileList
(
filePath
:
String
):
MutableMap
<
String
,
Any
>
{
fun
fileListRes
(
filePath
:
String
):
MutableMap
<
String
,
Any
>
{
//root path
val
params
=
mutableMapOf
<
String
,
Any
>().
apply
{
this
[
"code"
]
=
200
}
if
(
filePath
==
"/"
)
{
val
data
=
mutableMapOf
<
String
,
Any
>().
apply
{
this
[
"
file
Path"
]
=
"/"
this
[
"
dir
Path"
]
=
"/"
this
[
"fileList"
]
=
createRootInfo
()
}
params
[
"data"
]
=
data
}
else
{
//not root path
val
data
=
mutableMapOf
<
String
,
Any
>().
apply
{
this
[
"
filePath"
]
=
filePath
this
[
"
dirPath"
]
=
FileManagerUtil
.
relativeRootPath
(
filePath
)
this
[
"fileList"
]
=
traverseDir
(
filePath
)
}
params
[
"data"
]
=
data
...
...
@@ -45,8 +46,8 @@ object FileListAction {
val
fileInfos
=
mutableListOf
<
FileInfo
>()
val
internalAppDataPath
=
PathUtils
.
getInternalAppDataPath
()
val
externalStoragePath
=
PathUtils
.
getExternalStoragePath
()
fileInfos
.
add
(
FileInfo
(
internalAppDataPath
,
FileUtils
.
getFileName
(
internalAppDataPath
),
"folder"
,
""
,
""
+
FileUtils
.
getFileLastModified
(
internalAppDataPath
),
true
))
fileInfos
.
add
(
FileInfo
(
externalStoragePath
,
FileUtils
.
getFileName
(
externalStoragePath
)
,
"folder"
,
""
,
""
+
FileUtils
.
getFileLastModified
(
externalStoragePath
),
true
))
fileInfos
.
add
(
FileInfo
(
FileManagerUtil
.
relativeRootPath
(
internalAppDataPath
)
,
FileUtils
.
getFileName
(
internalAppDataPath
),
"folder"
,
""
,
""
+
FileUtils
.
getFileLastModified
(
internalAppDataPath
),
true
))
fileInfos
.
add
(
FileInfo
(
FileManagerUtil
.
relativeRootPath
(
externalStoragePath
),
"external"
,
"folder"
,
""
,
""
+
FileUtils
.
getFileLastModified
(
externalStoragePath
),
true
))
return
fileInfos
}
...
...
@@ -58,8 +59,10 @@ object FileListAction {
val
dir
=
File
(
dirPath
)
if
(
FileUtils
.
isDir
(
dir
))
{
dir
.
listFiles
()
?.
forEach
{
file
->
val
fileInfo
=
FileInfo
(
file
.
path
,
file
.
name
,
if
(
FileUtils
.
isDir
(
file
))
{
val
fileInfo
=
FileInfo
(
FileManagerUtil
.
relativeRootPath
(
file
.
path
)
,
file
.
name
,
if
(
FileUtils
.
isDir
(
file
))
{
"folder"
}
else
if
(
dir
.
absolutePath
.
contains
(
"/databases"
))
{
"db"
}
else
{
FileUtils
.
getFileExtension
(
file
)
},
""
,
""
+
FileUtils
.
getFileLastModified
(
file
),
false
)
...
...
@@ -73,7 +76,7 @@ object FileListAction {
data class
FileInfo
(
val
file
Path
:
String
,
val
dir
Path
:
String
,
val
fileName
:
String
,
val
fileType
:
String
,
val
fileUri
:
String
,
...
...
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/action/file/IndexAction.kt
浏览文件 @
869e22ea
...
...
@@ -10,7 +10,7 @@ package com.didichuxing.doraemonkit.kit.filemanager.action.file
* ================================================
*/
object
IndexAction
{
fun
createIndexInfo
():
MutableMap
<
String
,
Any
>
{
fun
indexInfoRes
():
MutableMap
<
String
,
Any
>
{
return
mutableMapOf
<
String
,
Any
>().
apply
{
this
[
"code"
]
=
200
this
[
"data"
]
=
"请在www.dokit.cn里的控制台中的文件同步助手中使用该功能"
...
...
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/action/file/RenameFileAction.kt
浏览文件 @
869e22ea
...
...
@@ -12,7 +12,7 @@ import com.blankj.utilcode.util.FileUtils
* ================================================
*/
object
RenameFileAction
{
fun
renameRes
(
newName
:
String
,
filePath
:
String
):
MutableMap
<
String
,
Any
>
{
fun
rename
File
Res
(
newName
:
String
,
filePath
:
String
):
MutableMap
<
String
,
Any
>
{
val
response
=
mutableMapOf
<
String
,
Any
>()
if
(
FileUtils
.
isFileExists
(
filePath
))
{
FileUtils
.
rename
(
filePath
,
newName
)
...
...
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/action/file/SaveFileAction.kt
浏览文件 @
869e22ea
...
...
@@ -13,7 +13,7 @@ import com.blankj.utilcode.util.FileUtils
* ================================================
*/
object
SaveFileAction
{
fun
saveRes
(
content
:
String
,
filePath
:
String
):
MutableMap
<
String
,
Any
>
{
fun
save
File
Res
(
content
:
String
,
filePath
:
String
):
MutableMap
<
String
,
Any
>
{
val
response
=
mutableMapOf
<
String
,
Any
>()
if
(
FileUtils
.
isFileExists
(
filePath
))
{
FileIOUtils
.
writeFileFromString
(
filePath
,
content
,
false
)
...
...
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/action/file/UploadFileAction.kt
浏览文件 @
869e22ea
package
com.didichuxing.doraemonkit.kit.filemanager.action.file
import
com.blankj.utilcode.util.FileUtils
import
com.didichuxing.doraemonkit.kit.filemanager.FileManagerUtil
import
io.ktor.http.content.MultiPartData
import
io.ktor.http.content.PartData
import
io.ktor.http.content.forEachPart
...
...
@@ -34,7 +35,7 @@ object UploadFileAction {
val
response
=
mutableMapOf
<
String
,
Any
>()
filePart
?.
let
{
val
dirPath
=
formPart
?.
value
val
dirPath
=
FileManagerUtil
.
absoluteRootPath
(
formPart
?.
value
)
val
fileName
=
filePart
?.
originalFileName
val
file
=
File
(
"$dirPath${File.separator}$fileName"
)
...
...
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/bean/DirInfo.kt
浏览文件 @
869e22ea
...
...
@@ -9,5 +9,5 @@ package com.didichuxing.doraemonkit.kit.filemanager.bean
* 修订历史:
* ================================================
*/
data class
DirInfo
(
val
file
Path
:
String
,
val
fileName
:
String
)
{
data class
DirInfo
(
val
dir
Path
:
String
,
val
fileName
:
String
)
{
}
\ No newline at end of file
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/bean/RenameFileInfo.kt
浏览文件 @
869e22ea
...
...
@@ -9,4 +9,4 @@ package com.didichuxing.doraemonkit.kit.filemanager.bean
* 修订历史:
* ================================================
*/
data class
RenameFileInfo
(
val
filePath
:
String
,
val
oldName
:
String
,
val
newName
:
String
)
\ No newline at end of file
data class
RenameFileInfo
(
val
dirPath
:
String
,
val
oldName
:
String
,
val
newName
:
String
)
\ No newline at end of file
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/bean/SaveFileInfo.kt
浏览文件 @
869e22ea
...
...
@@ -9,4 +9,4 @@ package com.didichuxing.doraemonkit.kit.filemanager.bean
* 修订历史:
* ================================================
*/
data class
SaveFileInfo
(
val
filePath
:
String
,
val
fileName
:
String
,
val
content
:
String
)
\ No newline at end of file
data class
SaveFileInfo
(
val
dirPath
:
String
,
val
fileName
:
String
,
val
content
:
String
)
\ No newline at end of file
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/filemanager/sqlite/DBManager.kt
浏览文件 @
869e22ea
...
...
@@ -24,12 +24,12 @@ object DBManager {
private
val
sqliteDBs
:
MutableMap
<
String
,
SQLiteDB
>
=
mutableMapOf
()
private
fun
openDB
(
dbFactory
:
DBFactory
,
databasePath
:
String
,
password
:
String
?):
SQLiteDB
{
private
fun
openDB
(
dbFactory
:
DBFactory
,
databasePath
:
String
,
password
:
String
?):
SQLiteDB
?
{
return
if
(
sqliteDBs
.
containsKey
(
databasePath
))
{
sqliteDBs
[
"databasePath"
]
!!
sqliteDBs
[
"databasePath"
]
}
else
{
sqliteDBs
[
"databasePath"
]
=
dbFactory
.
create
(
DoraemonKit
.
APPLICATION
!!
.
applicationContext
,
databasePath
,
password
)
sqliteDBs
[
"databasePath"
]
!!
sqliteDBs
[
"databasePath"
]
}
}
...
...
@@ -40,16 +40,18 @@ object DBManager {
fun
getAllTableName
(
databasePath
:
String
,
password
:
String
?):
List
<
String
>
{
val
openDB
=
openDB
(
NormalDBFactory
(),
databasePath
,
password
)
val
tables
=
mutableListOf
<
String
>()
val
cursor
=
openDB
.
rawQuery
(
"SELECT name FROM sqlite_master WHERE type='table' OR type='view' ORDER BY name COLLATE NOCASE"
,
null
)
cursor
?.
let
{
if
(
it
.
moveToFirst
())
{
while
(!
it
.
isAfterLast
)
{
val
name
=
it
.
getString
(
0
)
tables
.
add
(
name
)
it
.
moveToNext
()
openDB
?.
let
{
db
->
val
cursor
=
db
.
rawQuery
(
"SELECT name FROM sqlite_master WHERE type='table' OR type='view' ORDER BY name COLLATE NOCASE"
,
null
)
cursor
?.
let
{
if
(
it
.
moveToFirst
())
{
while
(!
it
.
isAfterLast
)
{
val
name
=
it
.
getString
(
0
)
tables
.
add
(
name
)
it
.
moveToNext
()
}
}
it
.
close
()
}
it
.
close
()
}
return
tables
...
...
@@ -60,31 +62,39 @@ object DBManager {
*/
fun
getTableData
(
databasePath
:
String
,
password
:
String
?,
tableName
:
String
):
Map
<
String
,
Any
>
{
val
openDB
=
openDB
(
NormalDBFactory
(),
databasePath
,
password
)
val
tableFieldInfos
=
getTableFieldInfos
(
openDB
,
tableName
)
val
tableRows
=
getTableRows
(
openDB
,
tableName
,
tableFieldInfos
)
val
params
=
mutableMapOf
<
String
,
Any
>()
params
[
"fieldInfo"
]
=
tableFieldInfos
params
[
"rows"
]
=
tableRows
openDB
?.
let
{
db
->
val
tableFieldInfos
=
getTableFieldInfos
(
db
,
tableName
)
val
tableRows
=
getTableRows
(
db
,
tableName
,
tableFieldInfos
)
params
[
"fieldInfo"
]
=
tableFieldInfos
params
[
"rows"
]
=
tableRows
}
return
params
}
/**
* 插入数据
*/
fun
insertRow
(
databasePath
:
String
,
password
:
String
?,
tableName
:
String
,
rowDatas
:
List
<
RowFiledInfo
>):
Long
{
val
sqlite
=
openDB
(
NormalDBFactory
(),
databasePath
,
password
)
val
openDB
=
openDB
(
NormalDBFactory
(),
databasePath
,
password
)
if
(
rowDatas
.
isEmpty
())
{
return
-
1
}
val
contentValues
=
ContentValues
()
rowDatas
.
forEach
{
rowInfo
->
if
(
rowInfo
.
value
.
isNullOrBlank
())
{
contentValues
.
put
(
rowInfo
.
title
,
"null"
)
}
else
{
contentValues
.
put
(
rowInfo
.
title
,
rowInfo
.
value
)
openDB
?.
let
{
db
->
val
contentValues
=
ContentValues
()
rowDatas
.
forEach
{
rowInfo
->
if
(
rowInfo
.
value
.
isNullOrBlank
())
{
contentValues
.
put
(
rowInfo
.
title
,
"null"
)
}
else
{
contentValues
.
put
(
rowInfo
.
title
,
rowInfo
.
value
)
}
}
return
db
.
insert
(
"[$tableName]"
,
null
,
contentValues
)
}
return
sqlite
.
insert
(
"[$tableName]"
,
null
,
contentValues
)
return
-
1
}
...
...
@@ -92,67 +102,75 @@ object DBManager {
* 更新数据
*/
fun
updateRow
(
databasePath
:
String
,
password
:
String
?,
tableName
:
String
,
rowDatas
:
List
<
RowFiledInfo
>):
Int
{
val
sqlite
=
openDB
(
NormalDBFactory
(),
databasePath
,
password
)
val
openDB
=
openDB
(
NormalDBFactory
(),
databasePath
,
password
)
if
(
rowDatas
.
isEmpty
())
{
return
-
1
}
val
contentValues
=
ContentValues
()
var
whereClause
=
""
val
whereArgList
=
mutableListOf
<
String
>()
rowDatas
.
forEach
{
rowInfo
->
if
(
rowInfo
.
isPrimary
)
{
if
(
whereClause
.
isBlank
())
{
whereClause
=
"${rowInfo.title} =? "
}
else
{
whereClause
=
"$whereClause and ${rowInfo.title} =? "
}
whereArgList
.
add
(
if
(
rowInfo
.
value
.
isNullOrBlank
())
{
"null"
}
else
{
rowInfo
.
value
})
}
else
{
if
(
rowInfo
.
value
.
isNullOrBlank
())
{
contentValues
.
put
(
rowInfo
.
title
,
"null"
)
openDB
?.
let
{
db
->
val
contentValues
=
ContentValues
()
var
whereClause
=
""
val
whereArgList
=
mutableListOf
<
String
>()
rowDatas
.
forEach
{
rowInfo
->
if
(
rowInfo
.
isPrimary
)
{
if
(
whereClause
.
isBlank
())
{
whereClause
=
"${rowInfo.title} =? "
}
else
{
whereClause
=
"$whereClause and ${rowInfo.title} =? "
}
whereArgList
.
add
(
if
(
rowInfo
.
value
.
isNullOrBlank
())
{
"null"
}
else
{
rowInfo
.
value
})
}
else
{
contentValues
.
put
(
rowInfo
.
title
,
rowInfo
.
value
)
if
(
rowInfo
.
value
.
isNullOrBlank
())
{
contentValues
.
put
(
rowInfo
.
title
,
"null"
)
}
else
{
contentValues
.
put
(
rowInfo
.
title
,
rowInfo
.
value
)
}
}
}
val
whereArgs
=
whereArgList
.
toTypedArray
()
return
db
.
update
(
"[$tableName]"
,
contentValues
,
whereClause
,
whereArgs
)
}
val
whereArgs
=
whereArgList
.
toTypedArray
()
return
sqlite
.
update
(
"[$tableName]"
,
contentValues
,
whereClause
,
whereArgs
)
return
-
1
}
/**
* 删除数据
*/
fun
deleteRow
(
databasePath
:
String
,
password
:
String
?,
tableName
:
String
,
rowDatas
:
List
<
RowFiledInfo
>):
Int
{
val
sqlite
=
openDB
(
NormalDBFactory
(),
databasePath
,
password
)
val
openDB
=
openDB
(
NormalDBFactory
(),
databasePath
,
password
)
if
(
rowDatas
.
isEmpty
())
{
return
-
1
}
var
whereClause
=
""
val
whereArgList
=
mutableListOf
<
String
>()
rowDatas
.
forEach
{
rowInfo
->
if
(
rowInfo
.
isPrimary
)
{
if
(
whereClause
.
isBlank
())
{
whereClause
=
"${rowInfo.title} =? "
}
else
{
whereClause
=
"$whereClause and ${rowInfo.title} =? "
openDB
?.
let
{
db
->
var
whereClause
=
""
val
whereArgList
=
mutableListOf
<
String
>()
rowDatas
.
forEach
{
rowInfo
->
if
(
rowInfo
.
isPrimary
)
{
if
(
whereClause
.
isBlank
())
{
whereClause
=
"${rowInfo.title} =? "
}
else
{
whereClause
=
"$whereClause and ${rowInfo.title} =? "
}
whereArgList
.
add
(
if
(
rowInfo
.
value
.
isNullOrBlank
())
{
"null"
}
else
{
rowInfo
.
value
})
}
whereArgList
.
add
(
if
(
rowInfo
.
value
.
isNullOrBlank
())
{
"null"
}
else
{
rowInfo
.
value
})
}
val
whereArgs
=
whereArgList
.
toTypedArray
()
return
db
.
delete
(
"[$tableName]"
,
whereClause
,
whereArgs
)
}
val
whereArgs
=
whereArgList
.
toTypedArray
()
return
sqlite
.
delete
(
"[$tableName]"
,
whereClause
,
whereArgs
)
return
-
1
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录