1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- //
- // customDownloadCacheManager.m
- // 双子星云手机
- //
- // 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];
- return fileFolder;
- }else {
- HLog(@"创建下载plist文件失败!");
- return @"";
- }
- }
- /** 查询当前文件下载了多少 */
- + (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
|