|
|
|
@ -1,12 +1,17 @@ |
|
|
|
import 'dart:async'; |
|
|
|
import 'dart:io'; |
|
|
|
|
|
|
|
import 'package:flutter_blue_plus/flutter_blue_plus.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
import 'package:path_provider/path_provider.dart'; |
|
|
|
import 'package:wifi_iot/wifi_iot.dart'; |
|
|
|
|
|
|
|
import '../../../core/utils/ftpconnect/ftpconnect.dart'; |
|
|
|
import 'meeting_controller.dart'; |
|
|
|
|
|
|
|
class MeetingConnectController extends GetxController { |
|
|
|
final _meetingController = Get.find<MeetingController>(); |
|
|
|
|
|
|
|
RxString stateStr = '搜索中...'.obs; |
|
|
|
RxBool isRescan = false.obs; |
|
|
|
RxBool isImportedFiles = false.obs; |
|
|
|
@ -30,6 +35,11 @@ class MeetingConnectController extends GetxController { |
|
|
|
|
|
|
|
FTPConnect? _ftpConnect; |
|
|
|
|
|
|
|
RxBool isDownload = false.obs; |
|
|
|
RxDouble downloadProgress = 0.0.obs; |
|
|
|
RxInt totalReceived = 0.obs; |
|
|
|
RxInt fileSize = 0.obs; |
|
|
|
|
|
|
|
@override |
|
|
|
void onInit() { |
|
|
|
super.onInit(); |
|
|
|
@ -208,10 +218,44 @@ class MeetingConnectController extends GetxController { |
|
|
|
); |
|
|
|
await _ftpConnect?.connect(); |
|
|
|
_ftpConnect?.listCommand = ListCommand.LIST; |
|
|
|
List<FTPEntry>? _listDirectory = |
|
|
|
await _ftpConnect?.listDirectoryContent(); |
|
|
|
print(_listDirectory); |
|
|
|
List<FTPEntry>? listDirectory = await _ftpConnect?.listDirectoryContent(); |
|
|
|
if (listDirectory != null && listDirectory.isNotEmpty) { |
|
|
|
isDownload.value = true; |
|
|
|
int totalSize = listDirectory.fold( |
|
|
|
0, |
|
|
|
(sum, entry) => sum + (entry.size ?? 0), |
|
|
|
); |
|
|
|
for (var i = 0; i < listDirectory.length; i++) { |
|
|
|
stateStr.value = '共${listDirectory.length}个文件,正在下载第${i + 1}个文件...'; |
|
|
|
int previousSize = i > 0 ? listDirectory[i - 1].size ?? 0 : 0; |
|
|
|
FTPEntry element = listDirectory[i]; |
|
|
|
await _downloadFile(totalSize, previousSize, element); |
|
|
|
} |
|
|
|
stateStr.value = '下载完成,共${listDirectory.length}个文件'; |
|
|
|
_disconnect(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Future<void> _downloadFile( |
|
|
|
int totalSize, int previousSize, FTPEntry entry) async { |
|
|
|
final directory = await getApplicationDocumentsDirectory(); |
|
|
|
final directoryDir = Directory('${directory.path}/RecordingPen'); |
|
|
|
if (!await directoryDir.exists()) { |
|
|
|
await directoryDir.create(recursive: true); |
|
|
|
} |
|
|
|
final String filePath = '${directory.path}/RecordingPen/${entry.name}'; |
|
|
|
final File localFile = File(filePath); |
|
|
|
await _ftpConnect?.downloadFileWithRetry( |
|
|
|
entry.name, |
|
|
|
localFile, |
|
|
|
onProgress: (double progress, int received, int size) { |
|
|
|
downloadProgress.value = (previousSize + received) / totalSize; |
|
|
|
totalReceived.value = received; |
|
|
|
fileSize.value = size; |
|
|
|
}, |
|
|
|
); |
|
|
|
await _meetingController.insertMeetingAudio(entry.name, filePath, ''); |
|
|
|
} |
|
|
|
|
|
|
|
String _decodePassword(List<int> data) { |
|
|
|
|