0
点赞
收藏
分享

微信扫一扫

在Linux/Ubuntu/Debian中使用lscpu命令查看CPU信息

简单聊育儿 2024-06-01 阅读 14

热很。。热很。。。。夏天的城市只有热浪没有情怀。。。

来吧,come on。。。

 引用第三方库:

开发实现:

一、控制器实现

头文件控制器定义:

实现文件定义:

//
//  ZipRarViewController.m
//
//  Created by carbonzhao on 2024/5/28.
//

#import "ZipRarViewController.h"
#import "SSZipArchive.h"
#import "UIBreadView.h"

NS_ASSUME_NONNULL_BEGIN

@interface UINextTreeView : UIView
{
}
- (void)setDataSource:(NSMutableArray*)list checkActionBlock:(void (^)(NSDictionary *e))checkActionBlock;
@end

NS_ASSUME_NONNULL_END

typedef void (^SubTreeViewCheckedTreeBlock)(NSDictionary *e);

@interface UINextTreeView ()<UITableViewDelegate,UITableViewDataSource>
{
    NSMutableArray *dataList;
    UITableView *tview;
}
@property (nonatomic,copy) SubTreeViewCheckedTreeBlock ClickTreeBlock;
@end

@implementation UINextTreeView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self setupUI];
    }
    return self;
}


- (void)setFrame:(CGRect)frame
{
    [super setFrame:frame];
    if (tview)
    {
        [tview setFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
    }
}


- (void)setupUI
{
    dataList = [[NSMutableArray alloc] initWithCapacity:0];
    
    tview = [[UITableView alloc] initWithFrame:self.bounds];
    tview.backgroundColor = DSTextPlaceColor;
    tview.dataSource = self;
    tview.delegate = self;
//    tview.tableFooterView = [UIView new];
    tview.separatorColor = [UIColor clearColor];
    tview.estimatedRowHeight = 0;
    tview.estimatedSectionFooterHeight = 0;
    tview.estimatedSectionHeaderHeight = 0;
    [tview setShowsVerticalScrollIndicator:NO];
    [tview setShowsHorizontalScrollIndicator:NO];
//    [tview setBackgroundColor:[UIColor redColor]];
//    tview.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//        [weakSelf getListAllDing:@"refresh"];
//    }];
    
    [self addSubview:tview];
}

#pragma mark - action
- (void)setDataSource:(NSMutableArray*)list checkActionBlock:(void (^)(NSDictionary *e))checkActionBlock
{
    [self setClickTreeBlock:checkActionBlock];
    [dataList addObjectsFromArray:list];
    [tview reloadData];
}


- (void)reloadView
{
    dispatch_async(dispatch_get_main_queue(), ^{
        [self->tview reloadData];
    });
}


- (NSString *)docIcon:(NSString *)ext
{
    NSString *ex = [ext lowercaseString];
    if ([@[@"xls",@"xlsx"] containsObject:ex])
    {
        return @"icon_excel_new";
    }
    else if ([@[@"doc",@"docx"] containsObject:ex])
    {
        return @"icon_word_new";
    }
    else if ([@[@"pdf"] containsObject:ex])
    {
        return @"icon_pdf_new";
    }
    else if ([@[@"txt"] containsObject:ex])
    {
        return @"icon_txt_new";
    }
    else if ([@[@"png",@"jpg",@"jpeg"] containsObject:ex])
    {
        return @"icon_img_new";
    }
    else if ([@[@"mov",@"mp4",@"avi",@"mpeg",@"mkv",@"3gp",@"wmv",@"rmvb"] containsObject:ex])
    {
        return @"icon_mp4_new";
    }
    else if ([@[@"mp3",@"wav"] containsObject:ex])
    {
        return @"icon_mp3";
    }
    else if ([@[@"zip",@"rar"] containsObject:ex])
    {
        return @"icon_zip_new";
    }
    return @"";
}

#pragma mark - tableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return dataList.count;
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height = 58;
    return height;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    CGFloat height = [self tableView:tableView heightForRowAtIndexPath:indexPath];
    if (height > 0)
    {
        CGFloat x = 20;
        NSMutableDictionary *e = [dataList objectAtIndex:indexPath.row];
        
        kWeakSelf(self)
        NSString *dicon = [e boolForKey:@"isDir"]?@"icon_folder_icon":[self docIcon:[e stringForKey:@"ext"]];
        CGRect rt = CGRectMake(x, (height-30)/2, 30, 30);
        UIImageView *dirIcon = [[UIImageView alloc] initWithFrame:rt];
        [dirIcon setImage:IMAGE_INIM_NAME(dicon)];
        [cell.contentView addSubview:dirIcon];
        
        x += (rt.size.width + 10);
        NSString *name = [e stringForKey:@"fileName"];
        rt = CGRectMake(x, 0, tableView.frame.size.width-20-x-40, height);
        UILabel *label = [[UILabel alloc] initWithFrame:rt];
        [label setFont:Font_size(16)];
        [label setTextColor:RGBA(10, 10, 10, 1)];
        [label setText:name];
        [label setTextAlignment:NSTextAlignmentLeft];
        [cell.contentView addSubview:label];
        
        if ([e boolForKey:@"isDir"])
        {
            rt = CGRectMake(tableView.width-34, (height-14)/2, 14, 14);
            UIImageView *iconView = [[UIImageView alloc] initWithFrame:rt];
            [iconView setImage:IMAGE_INIM_NAME(@"icon_arrow")];
            [cell.contentView addSubview:iconView];
        }
        rt = CGRectMake(25, height-1, tableView.frame.size.width-25, 1);
        UIImageView *iconView = [[UIImageView alloc] initWithFrame:rt];
        [iconView setBackgroundColor:RGB(245, 245, 245)];
        [cell.contentView addSubview:iconView];
        
        rt = CGRectMake(0, 0, tableView.frame.size.width, height);
        iconView = [[UIImageView alloc] initWithFrame:rt];
        [iconView setBackgroundColor:RGB(245, 245, 245)];
        [cell setSelectedBackgroundView:iconView];
    }
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    return cell;
}
        
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSMutableDictionary *e = [dataList objectAtIndex:indexPath.row];
    self.ClickTreeBlock(e);
}
@end

@interface ZipRarViewController ()
@property (nonatomic,strong) UIBreadView *breview;
@end

@implementation ZipRarViewController

- (instancetype)init
{
    if (self = [super init])
    {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.breview = [UIBreadView breadViewWithFrame:CGRectMake(0, 0, ScreenWidth, self.safeAreaHeight) viewType:UIBreadViewBreadType];
    [self.view addSubview:self.breview];
    
    NSString *fileName = [self.filePath lastPathComponent]; //获取文件名称
    [self setTitle:[NSString stringWithFormat:@"%@预览",fileName]];
    if ([self.filePath.absoluteString hasPrefix:@"http"])
    {
        WeakSelf(self);
        [self showToastWithKeepAliveBlock:^(UIToastFenceView *waitView) {
            [waitView setViewMode:UIToastFenceViewModeCircle];
            [waitView setTitleText:@"下载中..."];
            
            NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
            
            AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
            NSURLRequest *request = [NSURLRequest requestWithURL:self.filePath];
            
            NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:^(NSProgress *downloadProgress){
                
                CGFloat completedUnitCount = downloadProgress.completedUnitCount*1.0;
                CGFloat totalUnitCount = downloadProgress.totalUnitCount*1.0;
                CGFloat percent = completedUnitCount/totalUnitCount;
                
                [waitView setProgress:percent];
                if (percent == 1.0)
                {
                    [waitView setViewMode:UIToastFenceViewModeText];
                    [waitView setTitleText:@"下载完成"];
                    [waitView dismiss:1.5];
                }
            } destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
                NSURL *url = [NSURL fileURLWithPath:userDocuments(@"docPathFile", fileName)];
                return url;
                
            } completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
                if (error) {
                    [waitView setViewMode:UIToastFenceViewModeText];
                    [waitView setTitleText:@"下载失败"];
                    [waitView dismiss:1.5];
                }
                else 
                {
                    [waitView dismiss];
                    NSURL *url = [NSURL fileURLWithPath:userDocuments(@"docPathFile", fileName)];
                    weakSelf.filePath = url;
                    [weakSelf toReadySource];
                }
            }];
            [downloadTask resume];
        }];
    }
    else
    {
        [self toReadySource];
    }
}

#pragma mark - 解压文件
- (void)toReadySource
{
    NSString *path = [self.filePath path];
    NSString *fileName = [[[self.filePath lastPathComponent] componentsSeparatedByString:@"."] firstObject];
    NSString *to = userDocuments(@"zipsPathFile", @"");
    to = [to stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@",self.fileFlag,fileName]];
    
    WeakSelf(self);
//    [[NSFileManager defaultManager] removeItemAtPath:to error:nil];
    if ([[NSFileManager defaultManager] fileExistsAtPath:to])
    {
        [self showToastBlock:^(UIToastFenceView *waitView) {
            
            [weakSelf readFiles:[to stringByAppendingPathComponent:fileName] fileName:fileName];
        }];
    }
    else
    {
        [self showToastBlock:^(UIToastFenceView *waitView)
        {
            [waitView setTitleText:@"解压中..."];
            BOOL flag = [SSZipArchive unzipFileAtPath:path toDestination:to];
            if (flag)
            {
                [weakSelf readFiles:[to stringByAppendingPathComponent:fileName] fileName:fileName];
            }
            else
            {
                [waitView setTitleText:@"解压失败"];
                [waitView waitForSeconds];
            }
        }];
    }
}


- (void)readFiles:(NSString *)path fileName:(NSString *)fileName
{
    NSMutableArray *list = [NSMutableArray arrayWithCapacity:0];
    NSFileManager *fm = [NSFileManager defaultManager];
    NSArray *subFilePath = [fm contentsOfDirectoryAtPath:path error:nil];
    for (NSString * fileName in subFilePath)
    {
        if (![fileName isEqualToString:@".DS_Store"])
        {
            NSMutableDictionary *e = [[NSMutableDictionary alloc] initWithCapacity:0];
            [e setObject:path forKey:@"path"];
            [e setObject:fileName forKey:@"fileName"];
            BOOL isDir = NO;
            [fm fileExistsAtPath:[path stringByAppendingPathComponent:fileName] isDirectory: &isDir];
            [e setObject:boolToStr(isDir) forKey:@"isDir"];
            [e setObject:[fileName pathExtension] forKey:@"ext"];
            [list addObject:e];
        }
    }
    
    WeakSelf(self);
    dispatch_sync_on_main_queue(^{
        NSBreadData *d = [[NSBreadData alloc] init];
        [d setTitle:fileName];
        [self.breview addBreadViewTitle:d withConfigBlock:^UIView * _Nullable(NSInteger index, BOOL * _Nonnull useAnimation)
        {
            UINextTreeView *b = [[UINextTreeView alloc] init];
            [b setDataSource:list checkActionBlock:^(NSDictionary *e) {
                NSString *p = [e stringForKey:@"path"];
                NSString *n = [e stringForKey:@"fileName"];
                if ([e boolForKey:@"isDir"])
                {
                    p = [p stringByAppendingPathComponent:n];
                    [weakSelf readFiles:p fileName:n];
                }
                else
                {
                    if (weakSelf.delegateBlock)
                    {
                        weakSelf.delegateBlock(e);
                    }
                }
            }];
            return b;
        }];
    });
}
@end

二、面包屑实现(控制器内部实现切换子页面视图)

头文件源码:

实现文件:

完毕,相关的资源文件自己寻找整理,这里就不贴了,相关的一些个人开发依赖,有兴趣的同学可以留言找我要! 

三、使用

 

举报

相关推荐

0 条评论