// // 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