webSocketManager+downloadThumbnailImage.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // webSocketManager+downloadThumbnailImage.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/6/20.
  6. //
  7. #import "webSocketManager+downloadThumbnailImage.h"
  8. @implementation webSocketManager (downloadThumbnailImage)
  9. - (void)begindownloadThumbnailImageFunBy:(couldPhoneFileModel *)couldPhoneFileMod
  10. {
  11. self.curDownloadThumbnailModel = couldPhoneFileMod;
  12. if(!self.curDownloadThumbnailModel
  13. || ![self.curDownloadThumbnailModel isKindOfClass:[couldPhoneFileModel class]]){
  14. return;
  15. }
  16. [self ApplyDownloadThumbnailFun];
  17. }
  18. #pragma mark 申请下载缩略图
  19. - (void)ApplyDownloadThumbnailFun
  20. {
  21. self.downloadThumbnailTaskUid = [iTools getTaskUidStr];
  22. if([self.downloadThumbnailTaskUid isEqualToString:self.backupsTaskUid]
  23. ||[self.downloadThumbnailTaskUid isEqualToString:self.taskUid]
  24. ||[self.downloadThumbnailTaskUid isEqualToString:self.downloadFileTaskUid])
  25. {//重新生成taskUid
  26. [self ApplyDownloadThumbnailFun];
  27. return;
  28. }
  29. NSString *fileName = [self.curDownloadThumbnailModel getFileNameFun];
  30. NSString*pathStr = [cachesFileManager getFilePathWithName:fileName type:DownLoadThumbnail];
  31. long didDownloadBytes = 0;
  32. NSFileManager *manager0 = [NSFileManager defaultManager];
  33. if([manager0 fileExistsAtPath:pathStr]) {
  34. NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:pathStr]; // 创建文件句柄
  35. if (fileHandle) {
  36. didDownloadBytes = [fileHandle seekToEndOfFile];
  37. // 关闭文件句柄
  38. [fileHandle closeFile];
  39. }
  40. }
  41. NSString * commandStr = [RCCommandHelp applyForDownloadThumbnailFileBy:self.downloadThumbnailTaskUid withFilePath:self.curDownloadThumbnailModel.path withPosition:didDownloadBytes];
  42. //[self.commandChannelManager rc_sendData:commandStr];
  43. }
  44. - (void)downloadThumbnailFileFunServiceResponseFun:(NSData *)fileData with:(BOOL)isDownloadDone
  45. {
  46. NSString *fileName = [self.curDownloadThumbnailModel getFileNameFun];
  47. NSString*pathStr = [cachesFileManager getFilePathWithName:fileName type:DownLoadThumbnail];
  48. NSFileManager *manager0 = [NSFileManager defaultManager];
  49. long long endOfFile = 0;
  50. if(![manager0 fileExistsAtPath:pathStr]) {
  51. [cachesFileManager getFileNameWithContent:fileData fileName:fileName type:DownLoadThumbnail];
  52. }
  53. else{
  54. NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:pathStr]; // 创建文件句柄
  55. if (fileHandle) {
  56. endOfFile = [fileHandle seekToEndOfFile];
  57. if (endOfFile >= 0) {
  58. //if(endOfFile == self.curDownloadThumbnailModel.didDownloadBytes){
  59. [fileHandle writeData:fileData];
  60. //}
  61. }
  62. endOfFile = [fileHandle seekToEndOfFile];
  63. // 关闭文件句柄
  64. [fileHandle closeFile];
  65. }
  66. }
  67. long didDownloadBytes = fileData.length;
  68. if(endOfFile > 0){
  69. didDownloadBytes = endOfFile;
  70. }
  71. //self.curDownloadThumbnailModel.didDownloadBytes = didDownloadBytes;
  72. [[downloadThumbnailManager shareInstance] DownloadFileDoneOneFileFun];
  73. }
  74. @end