Skip to content

Commit

Permalink
Merge pull request #43 from kkroid/download-folder
Browse files Browse the repository at this point in the history
添加文件夹下载功能
  • Loading branch information
modstart authored Jan 12, 2025
2 parents c0925e6 + 121472c commit e1e0438
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/components/Device/DeviceFileManagerDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,40 @@ const doUpload = async () => {
const doDownload = async () => {
const path = await window.$mapi.file.openDirectory()
if (path) {
const files = checkedFileOnlyRecords.value
const files = checkedFileRecords.value
Dialog.loadingOn(t('正在下载'))
for (let f of files) {
await window.$mapi.adb.filePull(device.value.id, filePath.value + '/' + f.name, path + '/' + f.name)
const sourcePath = filePath.value + '/' + f.name
const targetPath = path + '/' + f.name
if (f.isDirectory) {
await downloadDirectory(device.value.id, sourcePath, targetPath)
} else {
await window.$mapi.adb.filePull(device.value.id, sourcePath, targetPath)
}
}
Dialog.loadingOff()
Dialog.tipSuccess(t('下载成功'))
}
}
const downloadDirectory = async (deviceId: string, sourcePath: string, targetPath: string) => {
// 创建目标文件夹
await window.$mapi.file.mkdir(targetPath, { isFullPath: true });
// 获取源文件夹内容
const files = await window.$mapi.adb.fileList(deviceId, sourcePath);
for (let f of files) {
const newSourcePath = sourcePath + '/' + f.name;
const newTargetPath = targetPath + '/' + f.name;
if (f.type === 'directory') {
console.log('download directory:', sourcePath, targetPath);
await downloadDirectory(deviceId, newSourcePath, newTargetPath);
} else {
console.log('download file:', sourcePath, targetPath);
await window.$mapi.adb.filePull(deviceId, newSourcePath, newTargetPath);
}
}
}
defineExpose({
show
})
Expand Down Expand Up @@ -217,8 +241,7 @@ const toggleSortByModifiedTime = () => {
{{ $t('上传') }}
</a-button>
<a-button class="mr-1"
@click="doDownload"
:disabled="checkedFileOnlyRecords.length===0">
@click="doDownload">
<template #icon>
<icon-download/>
</template>
Expand Down

0 comments on commit e1e0438

Please sign in to comment.