123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- //
- // webSocketManager+downloadThumbnailImage.m
- // 双子星云手机
- //
- // Created by xd h on 2024/6/20.
- //
- #import "webSocketManager+downloadThumbnailImage.h"
- @implementation webSocketManager (downloadThumbnailImage)
- - (void)begindownloadThumbnailImageFunBy:(couldPhoneFileModel *)couldPhoneFileMod
- {
- self.curDownloadThumbnailModel = couldPhoneFileMod;
-
- if(!self.curDownloadThumbnailModel
- || ![self.curDownloadThumbnailModel isKindOfClass:[couldPhoneFileModel class]]){
- return;
- }
-
- [self ApplyDownloadThumbnailFun];
- }
- #pragma mark 申请下载缩略图
- - (void)ApplyDownloadThumbnailFun
- {
-
- self.downloadThumbnailTaskUid = [iTools getTaskUidStr];
-
- if([self.downloadThumbnailTaskUid isEqualToString:self.backupsTaskUid]
- ||[self.downloadThumbnailTaskUid isEqualToString:self.taskUid]
- ||[self.downloadThumbnailTaskUid isEqualToString:self.downloadFileTaskUid])
- {//重新生成taskUid
- [self ApplyDownloadThumbnailFun];
- return;
- }
-
- NSString *fileName = [self.curDownloadThumbnailModel getFileNameFun];
- NSString*pathStr = [cachesFileManager getFilePathWithName:fileName type:DownLoadThumbnail];
- long didDownloadBytes = 0;
-
- NSFileManager *manager0 = [NSFileManager defaultManager];
- if([manager0 fileExistsAtPath:pathStr]) {
- NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:pathStr]; // 创建文件句柄
- if (fileHandle) {
- didDownloadBytes = [fileHandle seekToEndOfFile];
- // 关闭文件句柄
- [fileHandle closeFile];
- }
- }
-
- NSString * commandStr = [RCCommandHelp applyForDownloadThumbnailFileBy:self.downloadThumbnailTaskUid withFilePath:self.curDownloadThumbnailModel.path withPosition:didDownloadBytes];
- //[self.commandChannelManager rc_sendData:commandStr];
- }
- - (void)downloadThumbnailFileFunServiceResponseFun:(NSData *)fileData with:(BOOL)isDownloadDone
- {
-
- NSString *fileName = [self.curDownloadThumbnailModel getFileNameFun];
-
- NSString*pathStr = [cachesFileManager getFilePathWithName:fileName type:DownLoadThumbnail];
-
- NSFileManager *manager0 = [NSFileManager defaultManager];
- long long endOfFile = 0;
-
- if(![manager0 fileExistsAtPath:pathStr]) {
- [cachesFileManager getFileNameWithContent:fileData fileName:fileName type:DownLoadThumbnail];
- }
- else{
- NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:pathStr]; // 创建文件句柄
- if (fileHandle) {
- endOfFile = [fileHandle seekToEndOfFile];
- if (endOfFile >= 0) {
- //if(endOfFile == self.curDownloadThumbnailModel.didDownloadBytes){
- [fileHandle writeData:fileData];
- //}
- }
-
- endOfFile = [fileHandle seekToEndOfFile];
- // 关闭文件句柄
- [fileHandle closeFile];
- }
- }
-
- long didDownloadBytes = fileData.length;
- if(endOfFile > 0){
- didDownloadBytes = endOfFile;
- }
-
- //self.curDownloadThumbnailModel.didDownloadBytes = didDownloadBytes;
-
- [[downloadThumbnailManager shareInstance] DownloadFileDoneOneFileFun];
-
- }
- @end
|