123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- //
- // customDownloadCacheManager.m
- // Private-X
- //
- // Created by xd h on 2024/7/1.
- //
- #import "customDownloadCacheManager.h"
- #import "customDownloadManager.h"
- static NSMutableDictionary *_downloadList;
- @implementation customDownloadCacheManager
- #pragma mark-plist
- + (NSString *)getFullDirector {
- NSString *account = [customDownloadManager shareManager].uid;
- if (account.length != 0)
- {
- NSString *fileFolder = [HWDataManager documentPathForAccount:account fileFolder:KCustomDownloadDirector];
- // 创建文件储存路径
- if (![[NSFileManager defaultManager] fileExistsAtPath:fileFolder]) {
- [[NSFileManager defaultManager] createDirectoryAtPath:fileFolder withIntermediateDirectories:YES attributes:nil error:nil];
- }
- return fileFolder;
- }else {
- HLog(@"创建下载plist文件失败!");
- return @"";
- }
- }
- /** 上传的fullPath 是不能用的 要改新的*/
- + (NSString *)getFullPathByOldFullPath:(NSString*)fullPath
- {
- NSArray *pathArr= [fullPath componentsSeparatedByString:@"/"];
- NSString * fileName= @"";
-
- if(pathArr && pathArr.count >0){
- fileName = pathArr.lastObject;
- }
- else{
- return @"";
- }
-
- NSString* fileFullDir = [customDownloadCacheManager getFullDirector];
- NSString* curFullPath = [fileFullDir stringByAppendingPathComponent:fileName];
-
- return curFullPath;
- }
- /** 查询当前文件下载了多少 */
- + (int64_t)getFileSizeWithURL:(NSString *)url
- {
- NSString* fileFullDir = [customDownloadCacheManager getFullDirector];
-
- // 拼接后缀名
- NSString *urlFileName = [url lastPathComponent];
- NSString * decodeUrlFileName= [urlFileName stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
- // 设置下载路径
- NSString*fullPath = [fileFullDir stringByAppendingPathComponent:decodeUrlFileName];
-
- // 获取下载进度
- NSDictionary *fileInfo = [[NSFileManager defaultManager] attributesOfItemAtPath:fullPath error:nil];
- // 获取已下载的长度
- return [fileInfo[NSFileSize] longLongValue];
- }
- /** 删除配置信息 */
- + (BOOL)deleteFileWithUrl:(NSString *)url {
-
- BOOL flag = NO;
-
- @synchronized (self) {
- // 删除缓存的文件
- NSString *fileFolder = [customDownloadCacheManager getFullDirector];
- NSString *urlFileName = [url lastPathComponent];
- NSString * decodeUrlFileName= [urlFileName stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- NSString *fileName = decodeUrlFileName;
- NSString *fileURL = [fileFolder stringByAppendingPathComponent:fileName];
- flag= [[NSFileManager defaultManager] removeItemAtPath:fileURL error:nil];
- }
- return (flag);
- }
- #pragma mark -
- + (BOOL)clearDisks {
- // 1.删除所有的文件下载信息关联表
- // 2.删除cache 下的download文件夹
- return [[NSFileManager defaultManager] removeItemAtPath:KCustomFullDirector error:nil];
-
- }
- /** 取消所有当前下载的文件 清理内存缓存的数据 */
- + (BOOL)clearMemory {
- // 删除信息关联
- _downloadList = nil;
-
- return YES;
- }
- /** 取消所有当前下载的文件 删除磁盘所有的下载 清理内存缓存的数据 */
- + (BOOL)clearMemoryAndDisk {
- return ([self clearMemory] && [self clearDisks]);
- }
- @end
|