// // mineViewController.m // 双子星云手机 // // Created by xd h on 2024/6/21. // #import "mineViewController.h" #import "MineCommonUsedView.h" #import "privacyModeViewController.h" #import "TipsQRCodeForChangeDeviceViewController.h" #import "AboutViewController.h" #import "clearCacheAlretViewController.h" #import "inputPWDViewController.h" #import "customerServiceViewController.h" #import "customDownloadCacheManager.h" @interface mineViewController () @property(nonatomic,strong)UIButton *netButton; @property(nonatomic,strong)UILabel *snLabel; @property(nonatomic,strong)MineCommonUsedView *MineCommonUsedV; @end @implementation mineViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self.view setBackgroundColor:HWF5F7FAColor]; [self.toolBar setHidden:YES]; [self.navigationBar setHidden:YES]; [self.navBarBGView setHidden:YES]; [self drawAnyView]; } - (void)drawAnyView{ //顶底底部图片 UIImageView *topImageV = [UIImageView new]; topImageV.image = [UIImage imageNamed:@"Nas_top_img"]; [self.view addSubview:topImageV]; [topImageV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.height.mas_equalTo(280.0*AUTOSCALE); }]; //商标图片 UIImageView *TipImageV = [UIImageView new]; TipImageV.image = [UIImage imageNamed:@"mine_head_icon"]; [self.view addSubview:TipImageV]; [TipImageV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(68); make.left.mas_equalTo(16); make.width.mas_equalTo(48); make.height.mas_equalTo(48); }]; _netButton = [[UIButton alloc] init]; [_netButton setImage:[UIImage imageNamed:@"mine_net_icon"] forState:UIControlStateNormal]; [_netButton setTitleColor:[UIColor hwColor:@"#058DFB"] forState:UIControlStateNormal]; _netButton.titleLabel.font = [UIFont systemFontOfSize:12.0]; //_netButton.tag = 1; //[_netButton addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside]; _netButton.userInteractionEnabled = NO; [self.view addSubview:_netButton]; _netButton.layer.cornerRadius = 12; _netButton.layer.borderWidth = 1.5; _netButton.layer.borderColor = [UIColor hwColor:@"#058DFB"].CGColor; _netButton.layer.masksToBounds = YES; [_netButton mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(58); make.height.mas_equalTo(24); make.right.mas_equalTo(-16); make.centerY.mas_equalTo(TipImageV.mas_centerY).offset(0); }]; _snLabel = [[UILabel alloc] init]; _snLabel.font = [UIFont boldSystemFontOfSize:14.0]; _snLabel.textColor = [UIColor hwColor:@"#0A132B"]; //_fileNamelabel.backgroundColor = [UIColor greenColor]; [self.view addSubview:_snLabel]; [_snLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(TipImageV.mas_right).offset(5); make.right.equalTo(_netButton.mas_left).offset(-5); make.centerY.mas_equalTo(TipImageV.mas_centerY).offset(0); }]; //常用功能 _MineCommonUsedV = [[MineCommonUsedView alloc] init]; [self.view addSubview:_MineCommonUsedV]; [_MineCommonUsedV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(TipImageV.mas_bottom).offset(15); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.height.mas_equalTo(210); }]; KWeakSelf _MineCommonUsedV.didClickButtonFun = ^(NSInteger tag) { [weakSelf didClickCommonUsedFunBy:tag]; }; } #pragma mark 点击常用模块模块 - (void)didClickCommonUsedFunBy:(NSInteger)tag { switch (tag) { case 10:{ inputPWDViewController *nextVC = [inputPWDViewController new]; nextVC.isCheckPwdType = YES; [self pushViewController:nextVC animated:YES]; KWeakSelf nextVC.didInputRightPwdFun = ^{ [weakSelf gotoPrivacyModeVCFun]; }; } break; case 11:{ TipsQRCodeForChangeDeviceViewController *nextVC = [TipsQRCodeForChangeDeviceViewController new]; [self pushViewController:nextVC animated:YES]; } break; case 12:{ [[iToast makeText:@"点击了帮助与反馈"] show]; // shareRecordViewController *vc = [shareRecordViewController new]; // [self pushViewController:vc animated:YES]; } break; case 13:{ customerServiceViewController *vc = [customerServiceViewController new]; [self pushViewController:vc animated:YES]; } break; case 14:{ [[iToast makeText:@"点击了新手引导"] show]; } break; case 15:{ [self clickClearCacheButtonFun]; } break; case 16:{ AboutViewController *nextVC = [[AboutViewController alloc] init]; nextVC.getSysInfo = ^{ [[webSocketManager shareInstance] getSysInfoFun]; }; [self pushViewController:nextVC animated:YES]; } break; case 17:{ [[iToast makeText:@"点击了注销"] show]; } break; default: break; } } #pragma mark 去设置隐私 - (void)gotoPrivacyModeVCFun { privacyModeViewController *nextVC = [[privacyModeViewController alloc] init]; [self pushViewController:nextVC animated:YES]; } #pragma mark 清理缓存相关 - (void)clickClearCacheButtonFun { KWeakSelf /*弹窗提示清除缓存*/ clearCacheAlretViewController *nextVC = [[clearCacheAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_clear_cache",nil) msg:NSLocalizedString(@"clear_cache_tip",nil) imageStr:nil cancelTitle:NSLocalizedString(@"other_cancel",nil) okTitle:NSLocalizedString(@"other_clear",nil) isOkBtnHighlight:YES didClickOk:^(BOOL isSelect) { [weakSelf handleClearCacheFunWith:isSelect]; } didClickCancel:^{ }]; nextVC.modalPresentationStyle = UIModalPresentationCustom; [self presentViewController:nextVC animated:YES completion:^{ nextVC.view.superview.backgroundColor = [UIColor clearColor]; }]; } - (void)handleClearCacheFunWith:(BOOL)isSelectFileTransfer { [self ClearCommonCacheFun:isSelectFileTransfer]; //数据埋点 [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Clear_cache"]; } - (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]; NSString *downLoadNasDowmPath = [customDownloadCacheManager getFullDirector]; long logSize4 = [iTools folderSizeAtPath:downLoadNasDowmPath]; [[NSFileManager defaultManager] removeItemAtPath:downLoadNasDowmPath error:nil]; long clearTotal = logSize1 + logSize2 + logSize3 +logSize4 ; if(isSelectFileTransfer){ [self clearCacheByFileTransferFun:clearTotal]; } else{ [self showClearAllTipBy:clearTotal]; } } - (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){ [uploadFileManager shareInstance].curUploadFileDataModel.curUploadStateType = uploadStateSuspend; needReUploadingType = YES; } [[NSFileManager defaultManager] removeItemAtPath:ImagePath error:nil]; if(needReUploadingType){ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [uploadFileManager shareInstance].curUploadFileDataModel.curUploadStateType = uploadStateUploading; }); } //清理视频文件 NSString *videoPath = [NSString stringWithFormat:@"%@/Video",CachesPatch]; long vide0AllSizeBeforeClear = [iTools folderSizeAtPath:videoPath]; NSString *backupsingVideoName = nil; if([backupsFileManager shareInstance].curPhotosBackupsTaskMod && [backupsFileManager shareInstance].curPhotosBackupsTaskMod.curUploadFileType == uploadFileTypeVideo){ backupsingVideoName = [backupsFileManager shareInstance].curPhotosBackupsTaskMod.filename; } NSString *uploadingVideoName = nil; if([uploadFileManager shareInstance].curUploadFileDataModel && [uploadFileManager shareInstance].curUploadFileDataModel.curUploadFileType == uploadFileTypeVideo){ uploadingVideoName = [uploadFileManager shareInstance].curUploadFileDataModel.filename; } if(backupsingVideoName || uploadingVideoName){ NSMutableString *fileName = [NSMutableString new]; if(backupsingVideoName){ [fileName appendString:backupsingVideoName]; } if(uploadingVideoName){ if(fileName.length > 0){ [fileName appendString:@"|"]; } [fileName appendString:uploadingVideoName]; } [self deleteFilesInDirectoryAtPath:videoPath withOutFileName:fileName]; } else{ [[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 && ([downloadManager shareInstance].curDownloadFileModel.curDownloadStateType == downloadStateUploading ||[downloadManager shareInstance].curDownloadFileModel.curDownloadStateType == downloadStateSuspend)){ downLoadingFileName = [[downloadManager shareInstance].curDownloadFileModel getFileNameFun]; [self deleteFilesInDirectoryAtPath:downLoadingPath withOutFileName:downLoadingFileName]; } else{ [[NSFileManager defaultManager] removeItemAtPath:downLoadingPath error:nil]; } long downLoadingSizeAfterClear = [iTools folderSizeAtPath:downLoadingPath]; //清理数据库表 完成的 //下载完成 NSMutableString* where = [[NSMutableString alloc] initWithString:@"where "]; NSString *curStr = [NSString stringWithFormat:@"%@=%@ or %@=%@ ",bg_sqlKey(@"curDownloadStateType"),bg_sqlValue([NSNumber numberWithInt:downloadStateDone]),bg_sqlKey(@"curDownloadStateType"),bg_sqlValue([NSNumber numberWithInt:downloadStateFail])]; [where appendString:curStr]; [couldPhoneFileModel bg_deleteAsync:download_tableName where:where complete:^(BOOL isSuccess) { }]; //上传完成 NSMutableString* where2 = [[NSMutableString alloc] initWithString:@"where "]; NSString *curStr2 = [NSString stringWithFormat:@"%@=%@ or %@=%@ ",bg_sqlKey(@"curUploadStateType"),bg_sqlValue([NSNumber numberWithInt:uploadStateDone]), bg_sqlKey(@"curUploadStateType"),bg_sqlValue([NSNumber numberWithInt:uploadStateFail])]; [where2 appendString:curStr2]; [uploadFileDataModel bg_deleteAsync:upLoadFile_image_tableName where:where2 complete:^(BOOL isSuccess) { }]; long curTotolSize = (downLoadingSizeBeforeClear - downLoadingSizeAfterClear) + (vide0AllSizeBeforeClear - vide0AllSizeAfterClear) + imageAllSize + clearTotal; [self showClearAllTipBy:curTotolSize]; } - (BOOL)deleteFilesInDirectoryAtPath:(NSString *)path withOutFileName:(NSString*)fileNames { NSFileManager *fileManager = [NSFileManager defaultManager]; NSArray *fileNameArr = [fileNames componentsSeparatedByString:@"|"]; // 使用NSDirectoryEnumerator遍历目录 NSDirectoryEnumerator *directoryEnumerator = [fileManager enumeratorAtPath:path]; NSString *fileName; while ((fileName = [directoryEnumerator nextObject])) { BOOL canDelType = YES; for (NSString*noDelfileName in fileNameArr) { if([noDelfileName isEqualToString:fileName]){ canDelType = NO; break; } } if(canDelType){ NSString *filePath = [path stringByAppendingPathComponent:fileName]; // 如果是文件,则删除它 if ([fileManager fileExistsAtPath:filePath]) { BOOL success = [fileManager removeItemAtPath:filePath error:nil]; if (!success) { // 如果删除失败,返回NO并处理错误 return NO; } } } } // 所有文件都成功删除,返回YES return YES; } #pragma mark 数据设置 - (void)setDataFun { NSString *fullSNStr = [[NSString alloc] initWithFormat:@"SN:%@",[connectDeviceManager shareInstance].DeviceThirdIdMod.data.changeSn]; _snLabel.text = fullSNStr; NSString *NetButText = NSLocalizedString(@"mine_net_LAN",nil); if(![connectDeviceManager shareInstance].isPingOk){ NetButText = NSLocalizedString(@"mine_net_WAN",nil); } [_netButton setTitle:NetButText forState:UIControlStateNormal]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self setDataFun]; } - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; } - (void)pushViewController:(UIViewController*)vc animated:(BOOL)animated { [self.navigationController pushViewController:vc animated:animated]; } @end