DataUtils.m 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // DataUtils.m
  3. // UUTUtils
  4. //
  5. // Created by zhuge on 2017/12/22.
  6. // Copyright © 2017年 zhuge. All rights reserved.
  7. //
  8. #import "DataUtils.h"
  9. #import "ZGCommonUtils.h"
  10. #import "ProjectInfo.h"
  11. #import "ZGFileUtils.h"
  12. #define key_rootPath @"rootPath"
  13. @implementation DataUtils
  14. + (BOOL)isRootPathConfiged {
  15. return [[NSUserDefaults standardUserDefaults] stringForKey:key_rootPath] != nil;
  16. }
  17. + (NSString *)getRootPath {
  18. NSString *rootPath = [[NSUserDefaults standardUserDefaults] stringForKey:key_rootPath];
  19. if ([rootPath hasPrefix:@"~"]) {
  20. rootPath = [[ZGCommonUtils macUserPath] stringByAppendingString:[rootPath substringFromIndex:1]];
  21. }
  22. return rootPath;
  23. }
  24. + (NSMutableArray *)getAllProjects {
  25. NSMutableArray *ma = [NSMutableArray arrayWithCapacity:0];
  26. NSArray *arrDirs = [ZGFileUtils directorysAtDirNoRecursion:[DataUtils getRootPath]];
  27. for (NSString *dir in arrDirs) {
  28. ProjectInfo *bean = [ProjectInfo createWithDir:dir];
  29. [ma addObject:bean];
  30. }
  31. [ma sortUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
  32. ProjectInfo *p1 = obj1;
  33. ProjectInfo *p2 = obj2;
  34. return [p1.projectName compare:p2.projectName];
  35. }];
  36. return ma;
  37. }
  38. @end