Переглянути джерело

1.清除缓存添加具体数量

huangxiaodong 1 рік тому
батько
коміт
7153116703

+ 53 - 9
创维盒子/双子星云手机/Class/Set/MySetViewController.m

@@ -911,31 +911,67 @@
 
 - (void)handleClearCacheFunWith:(BOOL)isSelectFileTransfer
 {
-    [self ClearCommonCacheFun];
-    
-    if(isSelectFileTransfer){
-        [self clearCacheByFileTransferFun];
-    }
+    [self ClearCommonCacheFun:isSelectFileTransfer];
 }
 
-- (void)ClearCommonCacheFun
+- (void)ClearCommonCacheFun:(BOOL)isSelectFileTransfer
 {
     NSString *ruiyunLogPath = [NSString stringWithFormat:@"%@/logs/debug_0.log",CachesPatch];
+    long logSize1 = [iTools fileSizeAtPath:ruiyunLogPath];
     [[NSFileManager defaultManager] removeItemAtPath:ruiyunLogPath error:nil];
     
     NSString *appLogPath = [NSString stringWithFormat:@"%@/logs/app.log",CachesPatch];
+    long logSize2 = [iTools fileSizeAtPath:appLogPath];
+   
     [[NSFileManager defaultManager] removeItemAtPath:appLogPath error:nil];
     
     //
     NSString *downLoadThumbnailPath = [NSString stringWithFormat:@"%@/DownLoadThumbnail",CachesPatch];
+    long logSize3 = [iTools folderSizeAtPath:downLoadThumbnailPath];
+    
     [[NSFileManager defaultManager] removeItemAtPath:downLoadThumbnailPath error:nil];
+    
+    long clearTotal = logSize1 + logSize2 + logSize3;
+    
+    if(isSelectFileTransfer){
+        [self clearCacheByFileTransferFun:clearTotal];
+    }
+    else{
+        [self showClearAllTipBy:clearTotal];
+    }
+    
 }
 
-- (void)clearCacheByFileTransferFun
+- (void)showClearAllTipBy:(long)clearTotal
+{
+    long clearTotalK = clearTotal /1024;
+    
+    NSString *tipStr1 = NSLocalizedString(@"my_set_no_clear_finish",nil);
+    NSString *tipStr2 = @"";
+    
+    if(clearTotalK > 1024*1024){
+        tipStr2 = [[NSString alloc] initWithFormat:@"%.02fGB",clearTotalK/1024.0/1024.0];
+    }
+    else if(clearTotalK > 1024){
+        tipStr2 = [[NSString alloc] initWithFormat:@"%.02fMB",clearTotalK/1024.0];
+    }
+    else //if(clearTotalK > 0)
+    {
+        tipStr2 = [[NSString alloc] initWithFormat:@"%ldKB",clearTotalK];
+    }
+    
+    NSString *tipfullStr = [[NSString alloc] initWithFormat:@"%@%@",tipStr1,tipStr2];
+    //提示语
+    [[iToast makeText:tipfullStr] show];
+}
+
+- (void)clearCacheByFileTransferFun:(long)clearTotal
 {
     //清理图片
     BOOL needReUploadingType = NO;
     NSString *ImagePath = [NSString stringWithFormat:@"%@/Image",CachesPatch];
+    long imageAllSize = [iTools folderSizeAtPath:ImagePath];
+    
     if([uploadFileManager shareInstance].curUploadFileDataModel
        && [uploadFileManager shareInstance].curUploadFileDataModel.curUploadFileType == uploadFileTypeImage
        && [uploadFileManager shareInstance].curUploadFileDataModel.curUploadStateType == uploadStateUploading){
@@ -954,6 +990,7 @@
     
     //清理视频文件
     NSString *videoPath = [NSString stringWithFormat:@"%@/Video",CachesPatch];
+    long vide0AllSizeBeforeClear = [iTools folderSizeAtPath:videoPath];
     
     NSString *backupsingVideoName = nil;
     if([backupsFileManager shareInstance].curPhotosBackupsTaskMod
@@ -989,9 +1026,12 @@
         [[NSFileManager defaultManager] removeItemAtPath:videoPath error:nil];
     }
     
+    long vide0AllSizeAfterClear = [iTools folderSizeAtPath:videoPath];
+    
     
     //清理下载中
     NSString *downLoadingPath = [NSString stringWithFormat:@"%@/DownLoadFlie",CachesPatch];
+    long downLoadingSizeBeforeClear = [iTools folderSizeAtPath:downLoadingPath];
     
     NSString *downLoadingFileName = nil;
     if([downloadManager shareInstance].curDownloadFileModel
@@ -1005,6 +1045,9 @@
         [[NSFileManager defaultManager] removeItemAtPath:downLoadingPath error:nil];
     }
     
+    long downLoadingSizeAfterClear = [iTools folderSizeAtPath:downLoadingPath];
+    
+    
     //清理数据库表 完成的
     
     //下载完成
@@ -1023,8 +1066,9 @@
     [uploadFileDataModel bg_deleteAsync:upLoadFile_image_tableName where:where2 complete:^(BOOL isSuccess) {
     }];
     
-    //提示语
-    [[iToast makeText:NSLocalizedString(@"my_set_no_clear_finish",nil)] show];
+    long curTotolSize = (downLoadingSizeBeforeClear - downLoadingSizeAfterClear) + (vide0AllSizeBeforeClear - vide0AllSizeAfterClear) + imageAllSize + clearTotal;
+    
+    [self showClearAllTipBy:curTotolSize];
 }
 
 - (BOOL)deleteFilesInDirectoryAtPath:(NSString *)path withOutFileName:(NSString*)fileNames {

+ 5 - 0
创维盒子/双子星云手机/Helpers/iTools.h

@@ -159,6 +159,11 @@ NS_ASSUME_NONNULL_BEGIN
 
 // 时间戳转时间,时间戳为13位是精确到毫秒的,10位精确到秒
 + (NSString *)getDateStringWithTimeStr:(NSString* )str;
+
+// 文件夹大小(字节)
++ (unsigned long long)folderSizeAtPath:(NSString *)folderPath;
+//单个文件的大小(字节)
++(unsigned long long)fileSizeAtPath:(NSString *)filePath;
 @end
 
 NS_ASSUME_NONNULL_END

+ 23 - 0
创维盒子/双子星云手机/Helpers/iTools.m

@@ -1047,4 +1047,27 @@ static const char encodingTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopq
     return currentDateStr;
 }
 
+// 文件夹大小(字节)
++ (unsigned long long)folderSizeAtPath:(NSString *)folderPath{
+    NSFileManager *manager = [NSFileManager defaultManager];
+    if (![manager fileExistsAtPath:folderPath]) return 0;
+    NSEnumerator *childFilesEnumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];
+    NSString *fileName;
+    long long folderSize = 0;
+    while ((fileName = [childFilesEnumerator nextObject]) != nil){
+        NSString *fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];
+        folderSize += [self fileSizeAtPath:fileAbsolutePath];
+    }
+    return folderSize;
+}
+ 
+//单个文件的大小(字节)
++(unsigned long long)fileSizeAtPath:(NSString *)filePath {
+    NSFileManager *manager = [NSFileManager defaultManager];
+    if ([manager fileExistsAtPath:filePath]){
+        return [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
+    }
+    return 0;
+}
+
 @end