// // DataUtils.m // UUTUtils // // Created by zhuge on 2017/12/22. // Copyright © 2017年 zhuge. All rights reserved. // #import "DataUtils.h" #import "ZGCommonUtils.h" #import "ProjectInfo.h" #import "ZGFileUtils.h" #define key_rootPath @"rootPath" @implementation DataUtils + (BOOL)isRootPathConfiged { return [[NSUserDefaults standardUserDefaults] stringForKey:key_rootPath] != nil; } + (NSString *)getRootPath { NSString *rootPath = [[NSUserDefaults standardUserDefaults] stringForKey:key_rootPath]; if ([rootPath hasPrefix:@"~"]) { rootPath = [[ZGCommonUtils macUserPath] stringByAppendingString:[rootPath substringFromIndex:1]]; } return rootPath; } + (NSMutableArray *)getAllProjects { NSMutableArray *ma = [NSMutableArray arrayWithCapacity:0]; NSArray *arrDirs = [ZGFileUtils directorysAtDirNoRecursion:[DataUtils getRootPath]]; for (NSString *dir in arrDirs) { ProjectInfo *bean = [ProjectInfo createWithDir:dir]; [ma addObject:bean]; } [ma sortUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) { ProjectInfo *p1 = obj1; ProjectInfo *p2 = obj2; return [p1.projectName compare:p2.projectName]; }]; return ma; } @end