FLEXBundleExplorerViewController.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // FLEXBundleExplorerViewController.m
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 6/13/19.
  6. // Copyright © 2019 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXBundleExplorerViewController.h"
  9. #import "FLEXFileBrowserTableViewController.h"
  10. typedef NS_ENUM(NSUInteger, FLEXBundleExplorerRow) {
  11. FLEXBundleExplorerRowBundlePath = 1
  12. };
  13. @interface FLEXBundleExplorerViewController ()
  14. @property (nonatomic, readonly) NSBundle *bundleToExplore;
  15. @end
  16. @implementation FLEXBundleExplorerViewController
  17. - (NSBundle *)bundleToExplore
  18. {
  19. return (id)self.object;
  20. }
  21. - (NSArray<NSString *> *)shortcutPropertyNames
  22. {
  23. return @[@"bundleIdentifier", @"principalClass", @"infoDictionary",
  24. @"bundlePath", @"executablePath", @"loaded"];
  25. }
  26. - (NSArray *)customSectionRowCookies
  27. {
  28. BOOL isDirectory = NO;
  29. NSString *bundlePath = self.bundleToExplore.bundlePath;
  30. if ([NSFileManager.defaultManager fileExistsAtPath:bundlePath isDirectory:&isDirectory] && isDirectory) {
  31. return [@[@(FLEXBundleExplorerRowBundlePath)] arrayByAddingObjectsFromArray:[super customSectionRowCookies]];
  32. }
  33. return [super customSectionRowCookies];
  34. }
  35. - (NSString *)customSectionTitleForRowCookie:(id)rowCookie
  36. {
  37. if ([rowCookie isKindOfClass:[NSNumber class]]) {
  38. FLEXBundleExplorerRow row = [rowCookie unsignedIntegerValue];
  39. switch (row) {
  40. case FLEXBundleExplorerRowBundlePath:
  41. return @"Explore bundle directory";
  42. }
  43. } else {
  44. return [super customSectionTitleForRowCookie:rowCookie];
  45. }
  46. }
  47. - (NSString *)customSectionSubtitleForRowCookie:(id)rowCookie
  48. {
  49. if ([rowCookie isKindOfClass:[NSNumber class]]) {
  50. return nil;
  51. } else {
  52. return [super customSectionSubtitleForRowCookie:rowCookie];
  53. }
  54. }
  55. - (UIViewController *)customSectionDrillInViewControllerForRowCookie:(id)rowCookie
  56. {
  57. if ([rowCookie isKindOfClass:[NSNumber class]]) {
  58. FLEXBundleExplorerRow row = [rowCookie unsignedIntegerValue];
  59. switch (row) {
  60. case FLEXBundleExplorerRowBundlePath:
  61. return [[FLEXFileBrowserTableViewController alloc] initWithPath:self.bundleToExplore.bundlePath];
  62. }
  63. } else {
  64. return [super customSectionDrillInViewControllerForRowCookie:rowCookie];
  65. }
  66. }
  67. @end