This commit is contained in:
DDIsFriend
2023-08-23 09:24:40 +08:00
parent 6bd037c5dd
commit 63ca919ed5
494 changed files with 35308 additions and 6623 deletions

View File

@@ -0,0 +1,17 @@
//
// Example
// man
//
// Created by man 11/11/2018.
// Copyright © 2020 man. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "_FileInfo.h"
@interface _DirectoryContentsTableViewController : UIViewController
@property (nonatomic, assign, getter=isHomeDirectory) BOOL homeDirectory;
@property (nonatomic, strong) _FileInfo *fileInfo;
@end

View File

@@ -0,0 +1,741 @@
//
// Example
// man
//
// Created by man 11/11/2018.
// Copyright © 2020 man. All rights reserved.
//
#import "_DirectoryContentsTableViewController.h"
#import "_FilePreviewController.h"
#import "_FileTableViewCell.h"
#import "_ImageResources.h"
#import "_Sandboxer.h"
#import <QuickLook/QuickLook.h>
#import "_Sandboxer-Header.h"
#import "_NetworkHelper.h"
#import "_ImageController.h"
#import "_SandboxerHelper.h"
#import "NSObject+CocoaDebug.h"
@interface _DirectoryContentsTableViewController () <QLPreviewControllerDataSource, UIViewControllerPreviewingDelegate, UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate>
@property (nonatomic, strong) NSMutableArray<_FileInfo *> *dataSource;
@property (nonatomic, strong) NSMutableArray<_FileInfo *> *dataSource_cache;
@property (nonatomic, strong) NSMutableArray<_FileInfo *> *dataSource_search;
@property (nonatomic, strong) _FileInfo *previewingFileInfo;
@property (nonatomic, strong) _FileInfo *deletingFileInfo;
@property (nonatomic, strong) UIBarButtonItem *refreshItem;
@property (nonatomic, strong) UIBarButtonItem *editItem;
@property (nonatomic, strong) UIBarButtonItem *closeItem;
@property (nonatomic, strong) UIBarButtonItem *deleteAllItem;
@property (nonatomic, strong) UIBarButtonItem *deleteItem;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UISearchBar *searchBar;
@property (nonatomic, copy) NSString *randomId;
@property (nonatomic, copy) NSString *searchText;
@end
@implementation _DirectoryContentsTableViewController
//liman
- (void)customNavigationBar
{
//****** copy codes from LogNavigationViewController.swift ******
self.navigationController.navigationBar.translucent = NO;
self.navigationController.navigationBar.tintColor = [_NetworkHelper shared].mainColor;
self.navigationController.navigationBar.titleTextAttributes = @{
NSFontAttributeName:[UIFont boldSystemFontOfSize:20],
NSForegroundColorAttributeName: [_NetworkHelper shared].mainColor
};
//bugfix #issues-158
if (@available(iOS 13.0, *)) {
UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
[appearance configureWithOpaqueBackground];
appearance.shadowColor = [UIColor clearColor];
self.navigationController.navigationBar.standardAppearance = appearance;
self.navigationController.navigationBar.scrollEdgeAppearance = appearance;
}
//swift:
//bugfix #issues-158
// if #available(iOS 13, *) {
// let appearance = UINavigationBarAppearance()
// appearance.configureWithOpaqueBackground()
// // self.navigationController?.navigationBar.isTranslucent = true // pass "true" for fixing iOS 15.0 black bg issue
// // self.navigationController?.navigationBar.tintColor = UIColor.white // We need to set tintcolor for iOS 15.0
// appearance.shadowColor = .clear //removing navigationbar 1 px bottom border.
//// UINavigationBar.appearance().standardAppearance = appearance
//// UINavigationBar.appearance().scrollEdgeAppearance = appearance
// self.navigationBar.standardAppearance = appearance
// self.navigationBar.scrollEdgeAppearance = appearance
// }
}
- (void)exit {
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - View Lifecycle
- (void)dealloc {
[[_SandboxerHelper sharedInstance].searchTextDictionary removeObjectForKey:self.randomId];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.randomId = [_SandboxerHelper generateRandomId];
if (![_SandboxerHelper sharedInstance].searchTextDictionary) {
[_SandboxerHelper sharedInstance].searchTextDictionary = [NSMutableDictionary dictionary];
}
//
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapView)];
tap.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:tap];
//liman
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:31/255.0 green:33/255.0 blue:36/255.0 alpha:1.0];
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
//liman
if (_IsStringEmpty(self.title)) {
if (self.isHomeDirectory) {
[self customNavigationBar];//liman
self.title = @"Sandbox";
} else {
self.title = self.fileInfo.displayName;
}
}
//
[self setupViews];
[self registerForPreviewing];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.searchText = [[_SandboxerHelper sharedInstance].searchTextDictionary objectForKey:self.randomId];
[self loadDirectoryContents];
[self endEditing];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if (self.tableView.isEditing) {
[self.navigationController setToolbarHidden:YES animated:YES];
}
[self.searchBar resignFirstResponder];
}
#pragma mark - Private Methods
- (void)setupViews {
//not needed for now
self.editItem = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStylePlain target:self action:@selector(editAction)];
self.editItem.possibleTitles = [NSSet setWithObjects:@"Edit", @"Cancel", nil];
//
self.refreshItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(loadDirectoryContents)];
self.closeItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"_icon_file_type_close" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] style:UIBarButtonItemStyleDone target:self action:@selector(exit)];
if (self.homeDirectory) {
self.navigationItem.leftBarButtonItems = @[self.closeItem];
self.navigationItem.rightBarButtonItems = @[self.refreshItem];
} else {
self.navigationItem.rightBarButtonItems = @[self.closeItem, self.refreshItem];
}
//
self.view.backgroundColor = [UIColor blackColor];
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 44 - [UIApplication sharedApplication].statusBarFrame.size.height - 50) style:UITableViewStylePlain];
BOOL iPhoneX = NO;
if (@available(iOS 11.0, *)) {
UIWindow *mainWindow = [[UIApplication sharedApplication] keyWindow];
if (mainWindow.safeAreaInsets.top > 24.0) {
iPhoneX = YES;
}
}
if (iPhoneX) {
self.tableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 44 - [UIApplication sharedApplication].statusBarFrame.size.height - 50 - 34);
}
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.allowsMultipleSelectionDuringEditing = YES;
self.tableView.rowHeight = 60.0;
self.tableView.backgroundColor = [UIColor blackColor];
self.tableView.tableFooterView = [[UIView alloc] init];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.tableView registerClass:[_FileTableViewCell class] forCellReuseIdentifier:_FileTableViewCellReuseIdentifier];
[self.view addSubview:self.tableView];
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
self.searchBar.delegate = self;
self.searchBar.barTintColor = [UIColor blackColor];
self.searchBar.enablesReturnKeyAutomatically = NO;
[self.view addSubview:self.searchBar];
//hide searchBar icon
UITextField *textFieldInsideSearchBar = [self.searchBar valueForKey:@"searchField"];
textFieldInsideSearchBar.leftViewMode = UITextFieldViewModeNever;
textFieldInsideSearchBar.leftView = nil;
textFieldInsideSearchBar.backgroundColor = [UIColor whiteColor];
textFieldInsideSearchBar.returnKeyType = UIReturnKeyDefault;
}
- (void)registerForPreviewing {
if (_SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")) {
if (@available(iOS 9.0, *)) {
if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
[self registerForPreviewingWithDelegate:self sourceView:self.view];
}
} else {
// Fallback on earlier versions
}
}
}
- (void)loadDirectoryContents {
self.refreshItem.enabled = NO;
__weak _DirectoryContentsTableViewController *weakSelf = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
NSMutableArray<_FileInfo *> *dataSource_ = [_FileInfo contentsOfDirectoryAtURL:weakSelf.fileInfo.URL];
if ([dataSource_ count] > 0) {
weakSelf.dataSource = dataSource_;
weakSelf.dataSource_cache = dataSource_;
}
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.refreshItem.enabled = YES;
[weakSelf updateToolbarItems];
[weakSelf searchBar:weakSelf.searchBar textDidChange:weakSelf.searchBar.text];
});
});
[self.searchBar resignFirstResponder];
}
- (_FileInfo *)fileInfoAtIndexPath:(NSIndexPath *)indexPath {
return self.dataSource[indexPath.row];
}
- (UIViewController *)viewControllerWithFileInfo:(_FileInfo *)fileInfo {
if (fileInfo.isDirectory) {
_DirectoryContentsTableViewController *directoryContentsTableViewController = [[_DirectoryContentsTableViewController alloc] init];
directoryContentsTableViewController.fileInfo = fileInfo;
// directoryContentsTableViewController.hidesBottomBarWhenPushed = YES;//liman
return directoryContentsTableViewController;
} else {
if ([_Sandboxer shared].isShareable && fileInfo.isCanPreviewInQuickLook) {
//NSLog(@"Quick Look can preview this file");
self.previewingFileInfo = fileInfo;
QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.dataSource = self;
previewController.hidesBottomBarWhenPushed = YES;//liman
return previewController;
} else {
//liman
if (fileInfo.URL) {
NSData *data = [NSData dataWithContentsOfURL:fileInfo.URL];
if (data) {
UIImage *image = [UIImage imageWithGIFData:data];
if (image) {
_ImageController *vc = [[_ImageController alloc] initWithImage:image fileInfo:fileInfo];
vc.hidesBottomBarWhenPushed = YES;//liman
return vc;
}
}
}
//NSLog(@"Quick Look can not preview this file");
_FilePreviewController *filePreviewController = [[_FilePreviewController alloc] init];
filePreviewController.fileInfo = fileInfo;
filePreviewController.hidesBottomBarWhenPushed = YES;//liman
return filePreviewController;
}
}
}
- (BOOL)isCanDeleteAll {
if ((![_Sandboxer shared].isFileDeletable && ![_Sandboxer shared].isDirectoryDeletable) || self.dataSource.count == 0) {
return NO;
}
NSInteger fileCount = 0;
NSInteger directoryCount = 0;
[self getDeletableFileCount:&fileCount directoryCount:&directoryCount];
if (([_Sandboxer shared].isFileDeletable && ![_Sandboxer shared].isDirectoryDeletable && fileCount == 0) || // Can only delete files, but the number of files is 0
(![_Sandboxer shared].isFileDeletable && [_Sandboxer shared].isDirectoryDeletable && directoryCount == 0)) { // Can only delete folders, but the number of folders is 0
return NO;
}
return YES;
}
- (void)getDeletableFileCount:(NSInteger *)fileCount directoryCount:(NSInteger *)directoryCount {
NSInteger fc = 0;
NSInteger dc = 0;
for (_FileInfo *fileInfo in self.dataSource) {
if (fileInfo.isDirectory && [_Sandboxer shared].isDirectoryDeletable) {
dc++;
} else if (!fileInfo.isDirectory && [_Sandboxer shared].isFileDeletable) {
fc++;
}
}
*fileCount = fc;
*directoryCount = dc;
}
- (void)updateToolbarItems {
[self updateToolbarDeleteAllItem];
[self updateToolbarDeleteItem];
}
- (void)updateToolbarDeleteAllItem {
if (self.deleteAllItem) {
self.deleteAllItem.enabled = [self isCanDeleteAll];
}
}
- (void)updateToolbarDeleteItem {
if (self.deleteItem) {
self.deleteItem.enabled = self.tableView.indexPathsForSelectedRows.count > 0;
}
}
- (NSString *)messageForDeleteWithFileCount:(NSInteger)fileCount directoryCount:(NSInteger)directoryCount {
NSMutableString *message = [NSMutableString stringWithString:@"Are you sure to delete"];
if ([_Sandboxer shared].isFileDeletable && fileCount > 0) {
[message appendFormat:@"%ld files", (long)fileCount];
}
if ([_Sandboxer shared].isDirectoryDeletable && directoryCount > 0) {
if ([_Sandboxer shared].isFileDeletable && fileCount > 0) {
[message appendString:@","];
}
[message appendFormat:@"%ld directories", (long)directoryCount];
}
[message appendString:@"?"];
return message.copy;
}
#pragma mark - alert
- (UIAlertController *)alertControllerForDeleteWithMessage:(NSString *)message deleteHandler:(void (^ __nullable)(UIAlertAction *action))handler {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
[alert addAction:[UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDestructive handler:handler]];
alert.popoverPresentationController.permittedArrowDirections = 0;
alert.popoverPresentationController.sourceView = self.view;
alert.popoverPresentationController.sourceRect = CGRectMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height / 2.0, 0, 0);
return alert;
}
- (void)showAlert {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Not supported" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:cancelAction];
alert.popoverPresentationController.permittedArrowDirections = 0;
alert.popoverPresentationController.sourceView = self.view;
alert.popoverPresentationController.sourceRect = CGRectMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height / 2.0, 0, 0);
[self presentViewController:alert animated:YES completion:nil];
}
#pragma mark - target action
- (void)didTapView {
[self.searchBar resignFirstResponder];
}
- (void)editAction {
if (![_Sandboxer shared].isFileDeletable && ![_Sandboxer shared].isDirectoryDeletable) {
[self showAlert];
return;
}
if (!self.tableView.isEditing) {
[self beginEditing];
} else {
[self endEditing];
}
[self.searchBar resignFirstResponder];
}
- (void)beginEditing {
if (self.tableView.isEditing) { return; }
self.tableView.editing = YES;
self.editItem.title = @"Cancel";
self.editItem.style = UIBarButtonItemStyleDone;
[self.navigationController setToolbarHidden:NO animated:YES];
if (nil == self.deleteAllItem) {
self.deleteAllItem = [[UIBarButtonItem alloc] initWithTitle:@"Delete All" style:UIBarButtonItemStylePlain target:self action:@selector(deleteAllAction)];
self.deleteItem = [[UIBarButtonItem alloc] initWithTitle:@"Delete" style:UIBarButtonItemStylePlain target:self action:@selector(deleteSelectedFilesAction)];
//liman
[self.deleteAllItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateNormal];
[self.deleteItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateNormal];
[self.deleteAllItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:209/255.0 green:157/255.0 blue:157/255.0 alpha:1.0]} forState:UIControlStateHighlighted];
[self.deleteItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:209/255.0 green:157/255.0 blue:157/255.0 alpha:1.0]} forState:UIControlStateHighlighted];
[self setToolbarItems:@[self.deleteAllItem,
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
self.deleteItem] animated:YES];
}
[self updateToolbarItems];
}
- (void)endEditing {
if (!self.tableView.isEditing) { return; }
self.tableView.editing = NO;
self.editItem.title = @"Edit";
self.editItem.style = UIBarButtonItemStylePlain;
[self.navigationController setToolbarHidden:YES animated:YES];
}
- (void)deleteAllAction {
if (![self isCanDeleteAll]) {
return;
}
NSInteger fileCount = 0;
NSInteger directoryCount = 0;
[self getDeletableFileCount:&fileCount directoryCount:&directoryCount];
NSString *message = [self messageForDeleteWithFileCount:fileCount directoryCount:directoryCount];
UIAlertController *alert = [self alertControllerForDeleteWithMessage:message deleteHandler:^(UIAlertAction *action) {
[self deleteAllFiles];
}];
alert.popoverPresentationController.permittedArrowDirections = 0;
alert.popoverPresentationController.sourceView = self.view;
alert.popoverPresentationController.sourceRect = CGRectMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height / 2.0, 0, 0);
[self presentViewController:alert animated:YES completion:nil];
}
- (void)deleteSelectedFilesAction {
////NSLog(@"mlb - %@, title = %@", NSStringFromSelector(_cmd), self.title);
NSInteger fileCount = 0;
NSInteger directoryCount = 0;
for (NSIndexPath *indexPath in self.tableView.indexPathsForSelectedRows) {
_FileInfo *fileInfo = [self fileInfoAtIndexPath:indexPath];
////NSLog(@"mlb - Delete file: %@", fileInfo.displayName);
if (fileInfo.isDirectory) {
directoryCount++;
} else {
fileCount++;
}
}
NSString *message = [self messageForDeleteWithFileCount:fileCount directoryCount:directoryCount];
UIAlertController *alert = [self alertControllerForDeleteWithMessage:message deleteHandler:^(UIAlertAction *action) {
[self deleteSelectedFiles];
}];
alert.popoverPresentationController.permittedArrowDirections = 0;
alert.popoverPresentationController.sourceView = self.view;
alert.popoverPresentationController.sourceRect = CGRectMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height / 2.0, 0, 0);
[self presentViewController:alert animated:YES completion:nil];
}
- (void)deleteAllFiles {
////NSLog(@"mlb - %@, title = %@", NSStringFromSelector(_cmd), self.title);
NSMutableArray<_FileInfo *> *deletedFileInfos = [NSMutableArray arrayWithCapacity:self.dataSource.count];
NSMutableArray<NSIndexPath *> *deletedIndexPaths = [NSMutableArray arrayWithCapacity:self.dataSource.count];
[self.dataSource enumerateObjectsWithOptions:NSEnumerationReverse | NSEnumerationConcurrent usingBlock:^(_FileInfo * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([self deleteFile:obj]) {
////NSLog(@"mlb - %@, idx = %lu, obj = %@", NSStringFromSelector(_cmd), (unsigned long)idx, obj.displayName);
[deletedIndexPaths addObject:[NSIndexPath indexPathForRow:idx inSection:0]];
[deletedFileInfos addObject:obj];
}
}];
[self.dataSource removeObjectsInArray:deletedFileInfos];
//TODO... cache search
[self.tableView deleteRowsAtIndexPaths:deletedIndexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
[self endEditing];
}
- (void)deleteSelectedFiles {
////NSLog(@"mlb - %@, title = %@", NSStringFromSelector(_cmd), self.title);
NSMutableArray<_FileInfo *> *deletedFileInfos = [NSMutableArray arrayWithCapacity:self.tableView.indexPathsForSelectedRows.count];
for (NSIndexPath *indexPath in self.tableView.indexPathsForSelectedRows) {
_FileInfo *fileInfo = self.dataSource[indexPath.row];
if ([self deleteFile:fileInfo]) {
[deletedFileInfos addObject:fileInfo];
}
}
[self.dataSource removeObjectsInArray:deletedFileInfos];
//TODO... cache search
[self.tableView deleteRowsAtIndexPaths:self.tableView.indexPathsForSelectedRows withRowAnimation:UITableViewRowAnimationAutomatic];
[self endEditing];
}
- (void)deleteSelectedFile {
if ([self deleteFile:self.deletingFileInfo]) {
NSInteger index = -1;
index = [self.dataSource indexOfObject:self.deletingFileInfo];
[self.dataSource removeObject:self.deletingFileInfo];
if ([self.dataSource_cache count] > 0 && [self.dataSource_cache containsObject:self.deletingFileInfo]) {
[self.dataSource_cache removeObject:self.deletingFileInfo];
}
if ([self.dataSource_search count] > 0 && [self.dataSource_search containsObject:self.deletingFileInfo]) {
[self.dataSource_search removeObject:self.deletingFileInfo];
}
if (index >= 0) {
[self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
}
self.deletingFileInfo = nil;
}
}
- (BOOL)deleteFile:(_FileInfo *)fileInfo {
if (![_Sandboxer shared].isFileDeletable ||
(![_Sandboxer shared].isDirectoryDeletable && fileInfo.isDirectory)) {
return NO;
}
if ([[NSFileManager defaultManager] fileExistsAtPath:fileInfo.URL.path]) {
NSError *error;
[[NSFileManager defaultManager] removeItemAtURL:fileInfo.URL error:&error];
if (error) {
return NO;
}
}
return YES;
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
_FileTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:_FileTableViewCellReuseIdentifier forIndexPath:indexPath];
_FileInfo *fileInfo = [self fileInfoAtIndexPath:indexPath];
cell.imageView.image = [_ImageResources fileTypeImageNamed:fileInfo.typeImageName];
cell.textLabel.text = [_Sandboxer shared].isExtensionHidden ? fileInfo.displayName.stringByDeletingPathExtension : fileInfo.displayName;
// cell.accessoryType = fileInfo.isDirectory ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
cell.accessoryType = UITableViewCellAccessoryNone; //liman
//liman
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:fileInfo.modificationDateText];
if ([attributedString length] >= 25) {
[attributedString setAttributes:@{NSForegroundColorAttributeName: [_NetworkHelper shared].mainColor, NSFontAttributeName: [UIFont boldSystemFontOfSize:12]} range:NSMakeRange(0, 25)];
}
cell.detailTextLabel.attributedText = [attributedString copy];
// cell.detailTextLabel.text = fileInfo.modificationDateText;
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
if ([self fileInfoAtIndexPath:indexPath].isDirectory) {
return [_Sandboxer shared].isDirectoryDeletable;
} else {
return [_Sandboxer shared].isFileDeletable;
}
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
_FileInfo *fileInfo = [self fileInfoAtIndexPath:indexPath];
if (editingStyle == UITableViewCellEditingStyleDelete) {
////NSLog(@"Clicked delete editing style");
self.deletingFileInfo = fileInfo;
NSMutableString *message = [NSMutableString string];
if (fileInfo.isDirectory) {
[message appendFormat:@"Are you sure to delete this directory(including %lu files(or directories) inside)?", (unsigned long)fileInfo.filesCount];
} else {
[message appendString:@"Are you sure to delete this file?"];
}
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
[alert addAction:[UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
[self deleteSelectedFile];
}]];
alert.popoverPresentationController.permittedArrowDirections = 0;
alert.popoverPresentationController.sourceView = self.view;
alert.popoverPresentationController.sourceRect = CGRectMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height / 2.0, 0, 0);
[self presentViewController:alert animated:YES completion:nil];
}
}
#pragma mark - UITableViewDelegate
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return self.searchBar;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 44;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
_FileInfo *fileInfo = [self fileInfoAtIndexPath:indexPath];
if (tableView.isEditing) {
if ((fileInfo.isDirectory && ![_Sandboxer shared].isDirectoryDeletable) || (!fileInfo.isDirectory && ![_Sandboxer shared].isFileDeletable)) {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
} else {
[self updateToolbarDeleteItem];
}
} else {
[self.navigationController pushViewController:[self viewControllerWithFileInfo:fileInfo] animated:YES];
}
[self.searchBar resignFirstResponder];
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
_FileInfo *fileInfo = [self fileInfoAtIndexPath:indexPath];
if (tableView.isEditing) {
if ((fileInfo.isDirectory && ![_Sandboxer shared].isDirectoryDeletable) || (!fileInfo.isDirectory && ![_Sandboxer shared].isFileDeletable)) {
} else {
[self updateToolbarDeleteItem];
}
}
}
#pragma mark - QLPreviewControllerDataSource
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
return self.previewingFileInfo ? 1 : 0;
}
- (id<QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
return self.previewingFileInfo.URL;
}
#pragma mark - UIViewControllerPreviewingDelegate
/// Create a previewing view controller to be shown at "Peek".
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location {
// Obtain the index path and the cell that was pressed.
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
_FileTableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
if (!cell) { return nil; }
_FileInfo *fileInfo = [self fileInfoAtIndexPath:indexPath];
// Create a detail view controller and set its properties.
UIViewController *detailViewController = [self viewControllerWithFileInfo:fileInfo];
/*
Set the height of the preview by setting the preferred content size of the detail view controller.
Width should be zero, because it's not used in portrait.
*/
detailViewController.preferredContentSize = CGSizeZero;
// Set the source rect to the cell frame, so surrounding elements are blurred.
if (_SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")) {
if (@available(iOS 9.0, *)) {
previewingContext.sourceRect = cell.frame;
} else {
// Fallback on earlier versions
}
}
return detailViewController;
}
- (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {
[self showViewController:viewControllerToCommit sender:self];
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[self.searchBar resignFirstResponder];
}
#pragma mark - UISearchBarDelegate
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
[self.searchBar resignFirstResponder];
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
if (searchText && ![self.searchText isEqualToString:searchText]) {
[[_SandboxerHelper sharedInstance].searchTextDictionary setObject:searchText forKey:self.randomId];
}
if (!searchText || [searchText isEqualToString:@""]) {
self.dataSource = self.dataSource_cache;
[self.tableView reloadData];
return;
}
if (!self.dataSource_search) {
self.dataSource_search = [NSMutableArray array];
} else {
[self.dataSource_search removeAllObjects];
}
for (_FileInfo *obj in self.dataSource_cache) {
if ([[obj.displayName lowercaseString] containsString:[searchText lowercaseString]]) {
[self.dataSource_search addObject:obj];
}
}
self.dataSource = self.dataSource_search;
[self.tableView reloadData];
}
@end

60
Pods/CocoaDebug/Sources/Sandbox/_FileInfo.h generated Executable file
View File

@@ -0,0 +1,60 @@
//
// Example
// man
//
// Created by man 11/11/2018.
// Copyright © 2020 man. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSUInteger, _FileType) {
_FileTypeUnknown,
_FileTypeDirectory,
// Image
_FileTypeJPG, _FileTypePNG, _FileTypeGIF, _FileTypeSVG, _FileTypeBMP, _FileTypeTIF,
// Audio
_FileTypeMP3, _FileTypeAAC, _FileTypeWAV, _FileTypeOGG,
// Video
_FileTypeMP4, _FileTypeAVI, _FileTypeFLV, _FileTypeMIDI, _FileTypeMOV, _FileTypeMPG, _FileTypeWMV,
// Apple
_FileTypeDMG, _FileTypeIPA, _FileTypeNumbers, _FileTypePages, _FileTypeKeynote,
// Google
_FileTypeAPK,
// Microsoft
_FileTypeWord, _FileTypeExcel, _FileTypePPT, _FileTypeEXE, _FileTypeDLL,
// Document
_FileTypeTXT, _FileTypeRTF, _FileTypePDF, _FileTypeZIP, _FileType7z, _FileTypeCVS, _FileTypeMD,
// Programming
_FileTypeSwift, _FileTypeJava, _FileTypeC, _FileTypeCPP, _FileTypePHP,
_FileTypeJSON, _FileTypePList, _FileTypeXML, _FileTypeDatabase,
_FileTypeJS, _FileTypeHTML, _FileTypeCSS,
_FileTypeBIN, _FileTypeDat, _FileTypeSQL, _FileTypeJAR,
// Adobe
_FileTypeFlash, _FileTypePSD, _FileTypeEPS,
// Other
_FileTypeTTF, _FileTypeTorrent,
};
@interface _FileInfo : NSObject
@property (nonatomic, strong) NSURL *URL;
@property (nonatomic, strong) NSString *displayName;
@property (nonatomic, strong) NSString *extension;
@property (nonatomic, strong) NSString *modificationDateText;
@property (nonatomic, strong) NSDictionary<NSString *, id> *attributes;
@property (nonatomic, assign) _FileType type;
@property (nonatomic, assign, readonly) BOOL isDirectory;
@property (nonatomic, assign) NSUInteger filesCount; // File always 0
@property (nonatomic, strong, readonly) NSString *typeImageName;
@property (nonatomic, assign, readonly) BOOL isCanPreviewInQuickLook;
@property (nonatomic, assign, readonly) BOOL isCanPreviewInWebView;
- (instancetype)initWithFileURL:(NSURL *)URL;
+ (NSDictionary<NSString *, id> *)attributesWithFileURL:(NSURL *)URL;
+ (NSMutableArray<_FileInfo *> *)contentsOfDirectoryAtURL:(NSURL *)URL;
@end

365
Pods/CocoaDebug/Sources/Sandbox/_FileInfo.m generated Executable file
View File

@@ -0,0 +1,365 @@
//
// Example
// man
//
// Created by man 11/11/2018.
// Copyright © 2020 man. All rights reserved.
//
#import "_FileInfo.h"
#import "_Sandboxer.h"
#import "_SandboxerHelper.h"
#import "_Sandboxer-Header.h"
#import <QuickLook/QuickLook.h>
@interface _FileInfo ()
@property (nonatomic, strong, readwrite) NSString *typeImageName;
@end
@implementation _FileInfo
- (instancetype)initWithFileURL:(NSURL *)URL {
if (self = [super init]) {
self.URL = URL;
self.displayName = URL.lastPathComponent;
self.attributes = [_FileInfo attributesWithFileURL:URL];
if ([self.attributes.fileType isEqualToString:NSFileTypeDirectory]) {
self.type = _FileTypeDirectory;
self.filesCount = [_FileInfo contentCountOfDirectoryAtURL:URL];
//liman
if ([URL isFileURL]) {
self.modificationDateText = [NSString stringWithFormat:@"[%@] %@", [_SandboxerHelper fileModificationDateTextWithDate:self.attributes.fileModificationDate], [_SandboxerHelper sizeOfFolder:URL.path]];
}
} else {
self.extension = URL.pathExtension;
self.type = [_FileInfo fileTypeWithExtension:self.extension];
self.filesCount = 0;
//liman
if ([URL isFileURL]) {
self.modificationDateText = [NSString stringWithFormat:@"[%@] %@", [_SandboxerHelper fileModificationDateTextWithDate:self.attributes.fileModificationDate], [_SandboxerHelper sizeOfFile:URL.path]];
}
}
//liman
if ([self.modificationDateText containsString:@"[] "]) {
self.modificationDateText = [[self.modificationDateText mutableCopy] stringByReplacingOccurrencesOfString:@"[] " withString:@""];
}
}
return self;
}
#pragma mark - Getters
- (BOOL)isDirectory {
return self.type == _FileTypeDirectory;
}
- (NSString *)typeImageName {
if (!_typeImageName) {
switch (self.type) {
case _FileTypeUnknown: _typeImageName = @"icon_file_type_default"; break;
case _FileTypeDirectory: _typeImageName = self.filesCount == 0 ? @"icon_file_type_folder_empty" : @"icon_file_type_folder_not_empty"; break;
// Image
case _FileTypeJPG: _typeImageName = @"icon_file_type_jpg"; break;
case _FileTypePNG: _typeImageName = @"icon_file_type_png"; break;
case _FileTypeGIF: _typeImageName = @"icon_file_type_gif"; break;
case _FileTypeSVG: _typeImageName = @"icon_file_type_svg"; break;
case _FileTypeBMP: _typeImageName = @"icon_file_type_bmp"; break;
case _FileTypeTIF: _typeImageName = @"icon_file_type_tif"; break;
// Audio
case _FileTypeMP3: _typeImageName = @"icon_file_type_mp3"; break;
case _FileTypeAAC: _typeImageName = @"icon_file_type_aac"; break;
case _FileTypeWAV: _typeImageName = @"icon_file_type_wav"; break;
case _FileTypeOGG: _typeImageName = @"icon_file_type_ogg"; break;
// Video
case _FileTypeMP4: _typeImageName = @"icon_file_type_mp4"; break;
case _FileTypeAVI: _typeImageName = @"icon_file_type_avi"; break;
case _FileTypeFLV: _typeImageName = @"icon_file_type_flv"; break;
case _FileTypeMIDI: _typeImageName = @"icon_file_type_midi"; break;
case _FileTypeMOV: _typeImageName = @"icon_file_type_mov"; break;
case _FileTypeMPG: _typeImageName = @"icon_file_type_mpg"; break;
case _FileTypeWMV: _typeImageName = @"icon_file_type_wmv"; break;
// Apple
case _FileTypeDMG: _typeImageName = @"icon_file_type_dmg"; break;
case _FileTypeIPA: _typeImageName = @"icon_file_type_ipa"; break;
case _FileTypeNumbers: _typeImageName = @"icon_file_type_numbers"; break;
case _FileTypePages: _typeImageName = @"icon_file_type_pages"; break;
case _FileTypeKeynote: _typeImageName = @"icon_file_type_keynote"; break;
// Google
case _FileTypeAPK: _typeImageName = @"icon_file_type_apk"; break;
// Microsoft
case _FileTypeWord: _typeImageName = @"icon_file_type_doc"; break;
case _FileTypeExcel: _typeImageName = @"icon_file_type_xls"; break;
case _FileTypePPT: _typeImageName = @"icon_file_type_ppt"; break;
case _FileTypeEXE: _typeImageName = @"icon_file_type_exe"; break;
case _FileTypeDLL: _typeImageName = @"icon_file_type_dll"; break;
// Document
case _FileTypeTXT: _typeImageName = @"icon_file_type_txt"; break;
case _FileTypeRTF: _typeImageName = @"icon_file_type_rtf"; break;
case _FileTypePDF: _typeImageName = @"icon_file_type_pdf"; break;
case _FileTypeZIP: _typeImageName = @"icon_file_type_zip"; break;
case _FileType7z: _typeImageName = @"icon_file_type_7z"; break;
case _FileTypeCVS: _typeImageName = @"icon_file_type_cvs"; break;
case _FileTypeMD: _typeImageName = @"icon_file_type_md"; break;
// Programming
case _FileTypeSwift: _typeImageName = @"icon_file_type_swift"; break;
case _FileTypeJava: _typeImageName = @"icon_file_type_java"; break;
case _FileTypeC: _typeImageName = @"icon_file_type_c"; break;
case _FileTypeCPP: _typeImageName = @"icon_file_type_cpp"; break;
case _FileTypePHP: _typeImageName = @"icon_file_type_php"; break;
case _FileTypeJSON: _typeImageName = @"icon_file_type_json"; break;
case _FileTypePList: _typeImageName = @"icon_file_type_plist"; break;
case _FileTypeXML: _typeImageName = @"icon_file_type_xml"; break;
case _FileTypeDatabase: _typeImageName = @"icon_file_type_db"; break;
case _FileTypeJS: _typeImageName = @"icon_file_type_js"; break;
case _FileTypeHTML: _typeImageName = @"icon_file_type_html"; break;
case _FileTypeCSS: _typeImageName = @"icon_file_type_css"; break;
case _FileTypeBIN: _typeImageName = @"icon_file_type_bin"; break;
case _FileTypeDat: _typeImageName = @"icon_file_type_dat"; break;
case _FileTypeSQL: _typeImageName = @"icon_file_type_sql"; break;
case _FileTypeJAR: _typeImageName = @"icon_file_type_jar"; break;
// Adobe
case _FileTypeFlash: _typeImageName = @"icon_file_type_fla"; break;
case _FileTypePSD: _typeImageName = @"icon_file_type_psd"; break;
case _FileTypeEPS: _typeImageName = @"icon_file_type_eps"; break;
// Other
case _FileTypeTTF: _typeImageName = @"icon_file_type_ttf"; break;
case _FileTypeTorrent: _typeImageName = @"icon_file_type_torrent"; break;
}
}
return _typeImageName;
}
- (BOOL)isCanPreviewInQuickLook {
return [QLPreviewController canPreviewItem:self.URL];
}
- (BOOL)isCanPreviewInWebView {
if (// Image
self.type == _FileTypePNG ||
self.type == _FileTypeJPG ||
self.type == _FileTypeGIF ||
self.type == _FileTypeSVG ||
self.type == _FileTypeBMP ||
// Audio
self.type == _FileTypeWAV ||
// Apple
self.type == _FileTypeNumbers ||
self.type == _FileTypePages ||
self.type == _FileTypeKeynote ||
// Microsoft
self.type == _FileTypeWord ||
self.type == _FileTypeExcel ||
// Document
self.type == _FileTypeTXT ||
self.type == _FileTypePDF ||
self.type == _FileTypeMD ||
// Programming
self.type == _FileTypeJava ||
self.type == _FileTypeSwift ||
self.type == _FileTypeCSS ||
// Adobe
self.type == _FileTypePSD) {
return YES;
}
return NO;
}
#pragma mark - Public Methods
+ (NSDictionary<NSString *, id> *)attributesWithFileURL:(NSURL *)URL {
NSDictionary<NSString *, id> *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:URL.path error:nil];
return attributes;
}
+ (NSMutableArray<_FileInfo *> *)contentsOfDirectoryAtURL:(NSURL *)URL {
// ////NSLog(@"%@, url = %@", NSStringFromSelector(_cmd), URL.path);
NSMutableArray *fileInfos = [NSMutableArray array];
BOOL isDir = NO;
BOOL isExists = [[NSFileManager defaultManager] fileExistsAtPath:URL.path isDirectory:&isDir];
if (isExists && isDir) {
NSArray<NSString *> *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:URL.path error:nil];
if ([contents count] > 0) {
for (NSString *name in contents) {
if (_Sandboxer.shared.isSystemFilesHidden && [name hasPrefix:@"."]) { continue; }
_FileInfo *fileInfo = [[_FileInfo alloc] initWithFileURL:[URL URLByAppendingPathComponent:name]];
[fileInfos addObject:fileInfo];
}
}
}
return fileInfos;
}
+ (NSUInteger)contentCountOfDirectoryAtURL:(NSURL *)URL {
// ////NSLog(@"%@, url = %@", NSStringFromSelector(_cmd), URL.path);
NSUInteger count = 0;
BOOL isDir = NO;
BOOL isExists = [[NSFileManager defaultManager] fileExistsAtPath:URL.path isDirectory:&isDir];
if (isExists && isDir) {
NSArray<NSString *> *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:URL.path error:nil];
if ([contents count] > 0) {
for (NSString *name in contents) {
if (_Sandboxer.shared.isSystemFilesHidden && [name hasPrefix:@"."]) { continue; }
count++;
}
}
}
return count;
}
+ (_FileType)fileTypeWithExtension:(NSString *)extension {
_FileType type = _FileTypeUnknown;
if (_IsStringEmpty(extension)) {
return type;
}
// Image
if ([extension compare:@"jpg" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeJPG;
} else if ([extension compare:@"png" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypePNG;
} else if ([extension compare:@"gif" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeGIF;
} else if ([extension compare:@"svg" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeSVG;
} else if ([extension compare:@"bmp" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeBMP;
} else if ([extension compare:@"tif" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeTIF;
}
// Audio
else if ([extension compare:@"mp3" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeMP3;
} else if ([extension compare:@"aac" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeAAC;
} else if ([extension compare:@"wav" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeWAV;
} else if ([extension compare:@"ogg" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeOGG;
}
// Video
else if ([extension compare:@"mp4" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeMP4;
} else if ([extension compare:@"avi" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeAVI;
} else if ([extension compare:@"flv" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeFLV;
} else if ([extension compare:@"midi" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeMIDI;
} else if ([extension compare:@"mov" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeMOV;
} else if ([extension compare:@"mpg" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeMPG;
} else if ([extension compare:@"wmv" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeWMV;
}
// Apple
else if ([extension compare:@"dmg" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeDMG;
} else if ([extension compare:@"ipa" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeIPA;
} else if ([extension compare:@"numbers" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeNumbers;
} else if ([extension compare:@"pages" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypePages;
} else if ([extension compare:@"key" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeKeynote;
}
// Google
else if ([extension compare:@"apk" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeAPK;
}
// Microsoft
else if ([extension compare:@"doc" options:NSCaseInsensitiveSearch] == NSOrderedSame ||
[extension compare:@"docx" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeWord;
} else if ([extension compare:@"xls" options:NSCaseInsensitiveSearch] == NSOrderedSame ||
[extension compare:@"xlsx" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeExcel;
} else if ([extension compare:@"ppt" options:NSCaseInsensitiveSearch] == NSOrderedSame ||
[extension compare:@"pptx" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypePPT;
} else if ([extension compare:@"exe" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeEXE;
} else if ([extension compare:@"dll" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeDLL;
}
// Document
else if ([extension compare:@"txt" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeTXT;
} else if ([extension compare:@"rtf" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeRTF;
} else if ([extension compare:@"pdf" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypePDF;
} else if ([extension compare:@"zip" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeZIP;
} else if ([extension compare:@"7z" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileType7z;
} else if ([extension compare:@"cvs" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeCVS;
} else if ([extension compare:@"md" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeMD;
}
// Programming
else if ([extension compare:@"swift" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeSwift;
} else if ([extension compare:@"java" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeJava;
} else if ([extension compare:@"c" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeC;
} else if ([extension compare:@"cpp" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeCPP;
} else if ([extension compare:@"php" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypePHP;
} else if ([extension compare:@"json" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeJSON;
} else if ([extension compare:@"plist" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypePList;
} else if ([extension compare:@"xml" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeXML;
} else if ([extension compare:@"db" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeDatabase;
} else if ([extension compare:@"js" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeJS;
} else if ([extension compare:@"html" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeHTML;
} else if ([extension compare:@"css" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeCSS;
} else if ([extension compare:@"bin" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeBIN;
} else if ([extension compare:@"dat" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeDat;
} else if ([extension compare:@"sql" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeSQL;
} else if ([extension compare:@"jar" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeJAR;
}
// Adobe
else if ([extension compare:@"psd" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypePSD;
}
else if ([extension compare:@"eps" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeEPS;
}
// Other
else if ([extension compare:@"ttf" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeTTF;
} else if ([extension compare:@"torrent" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
type = _FileTypeTorrent;
}
return type;
}
@end

View File

@@ -0,0 +1,17 @@
//
// Example
// man
//
// Created by man 11/11/2018.
// Copyright © 2020 man. All rights reserved.
//
#import <UIKit/UIKit.h>
@class _FileInfo;
@interface _FilePreviewController : UIViewController
@property (nonatomic, strong) _FileInfo *fileInfo;
@end

View File

@@ -0,0 +1,225 @@
//
// Example
// man
//
// Created by man 11/11/2018.
// Copyright © 2020 man. All rights reserved.
//
#import "_FilePreviewController.h"
#import "_FileInfo.h"
#import <QuickLook/QuickLook.h>
#import <WebKit/WebKit.h>
#import "_Sandboxer-Header.h"
#import "_Sandboxer.h"
@interface _FilePreviewController () <QLPreviewControllerDataSource, WKNavigationDelegate, WKUIDelegate, UIDocumentInteractionControllerDelegate>
@property (nonatomic, strong) WKWebView *wkWebView;
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) UIActivityIndicatorView *activityIndicatorView;
@property (nonatomic, strong) UIDocumentInteractionController *documentInteractionController;
@end
@implementation _FilePreviewController
#pragma mark - View Lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
self.title = self.fileInfo.displayName.stringByDeletingPathExtension;
self.view.backgroundColor = [UIColor whiteColor];
[self init_documentInteractionController];
[self initDatas];
[self setupViews];
[self loadFile];
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
if (self.wkWebView) {
self.wkWebView.frame = self.view.bounds;
}
// if (self.webView) {
// self.webView.frame = self.view.bounds;
// }
if (self.textView) {
self.textView.frame = self.view.bounds;
}
self.activityIndicatorView.center = self.view.center;
}
#pragma mark - Private Methods
- (void)init_documentInteractionController {
if (!self.documentInteractionController) {
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:self.fileInfo.URL];
self.documentInteractionController.delegate = self;
self.documentInteractionController.name = self.fileInfo.displayName;
}
}
- (void)initDatas {
}
- (void)setupViews {
if ([_Sandboxer shared].isShareable) {
UIBarButtonItem *shareItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(sharingAction)];
self.navigationItem.rightBarButtonItem = shareItem;
}
if (self.fileInfo.isCanPreviewInWebView) {
self.wkWebView = [[WKWebView alloc] initWithFrame:self.view.bounds];
self.wkWebView.backgroundColor = [UIColor whiteColor];
self.wkWebView.navigationDelegate = self;
[self.view addSubview:self.wkWebView];
} else {
switch (self.fileInfo.type) {
case _FileTypePList: {
self.textView = [[UITextView alloc] initWithFrame:self.view.bounds];
self.textView.editable = NO;
self.textView.alwaysBounceVertical = YES;
[self.view addSubview:self.textView];
break;
}
default:
break;
}
}
[self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showOrHideNavigationBar)]];
self.activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[self.view addSubview:self.activityIndicatorView];
}
- (void)loadFile {
if (self.fileInfo.isCanPreviewInWebView) {
if (@available(iOS 9.0, *)) {
[self.wkWebView loadFileURL:self.fileInfo.URL allowingReadAccessToURL:self.fileInfo.URL];
} else {
// Fallback on earlier versions
}
} else {
switch (self.fileInfo.type) {
case _FileTypePList: {
[self.activityIndicatorView startAnimating];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *data = [NSData dataWithContentsOfFile:self.fileInfo.URL.path];
if (data) {
NSString *content = [[NSPropertyListSerialization propertyListWithData:data options:kNilOptions format:nil error:nil] description];
dispatch_async(dispatch_get_main_queue(), ^{
[self.activityIndicatorView stopAnimating];
self.textView.text = content;
});
} else {
dispatch_async(dispatch_get_main_queue(), ^{
[self.activityIndicatorView stopAnimating];
[self showAlert];
});
}
});
break;
}
default: {
[self showAlert];
}
break;
}
}
}
#pragma mark - alert
- (void)showAlert {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Not supported" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:cancelAction];
alert.popoverPresentationController.permittedArrowDirections = 0;
alert.popoverPresentationController.sourceView = self.view;
alert.popoverPresentationController.sourceRect = CGRectMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height / 2.0, 0, 0);
[self presentViewController:alert animated:YES completion:nil];
}
#pragma mark - Action
- (void)showOrHideNavigationBar {
[self.navigationController setNavigationBarHidden:!self.navigationController.isNavigationBarHidden animated:YES];
}
- (void)sharingAction {
if (![_Sandboxer shared].isShareable) { return; }
[self init_documentInteractionController];
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
[self.documentInteractionController presentOptionsMenuFromBarButtonItem:self.navigationItem.rightBarButtonItem animated:YES];
} else {
[self.documentInteractionController presentOptionsMenuFromRect:CGRectZero inView:self.view animated:YES];
}
}
#pragma mark - UIDocumentInteractionControllerDelegate
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
return self.navigationController;
}
- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller {
return self.view.bounds;
}
- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller {
return self.view;
}
#pragma mark - QLPreviewControllerDataSource
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
return 1;
}
- (id<QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
return self.fileInfo.URL;
}
#pragma mark - WKNavigationDelegate
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
////NSLog(@"%@", NSStringFromSelector(_cmd));
[self.activityIndicatorView startAnimating];
}
- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation {
////NSLog(@"%@", NSStringFromSelector(_cmd));
[self.activityIndicatorView stopAnimating];
}
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
////NSLog(@"%@", NSStringFromSelector(_cmd));
[self.activityIndicatorView stopAnimating];
}
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error {
////NSLog(@"%@, error = %@", NSStringFromSelector(_cmd), error);
[self.activityIndicatorView stopAnimating];
}
#pragma mark - WKUIDelegate
@end

View File

@@ -0,0 +1,15 @@
//
// Example
// man
//
// Created by man 11/11/2018.
// Copyright © 2020 man. All rights reserved.
//
#import <UIKit/UIKit.h>
UIKIT_EXTERN NSString *const _FileTableViewCellReuseIdentifier;
@interface _FileTableViewCell : UITableViewCell
@end

View File

@@ -0,0 +1,52 @@
//
// Example
// man
//
// Created by man 11/11/2018.
// Copyright © 2020 man. All rights reserved.
//
#import "_FileTableViewCell.h"
NSString *const _FileTableViewCellReuseIdentifier = @"_FileCell";
@implementation _FileTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
if (self) {
[self setupViews];
}
return self;
}
- (void)setupViews {
//liman
self.backgroundColor = [UIColor blackColor];
self.contentView.backgroundColor = [UIColor blackColor];
self.textLabel.textColor = [UIColor whiteColor];
self.textLabel.adjustsFontSizeToFitWidth = YES;
self.detailTextLabel.textColor = [UIColor systemGrayColor];
self.detailTextLabel.adjustsFontSizeToFitWidth = YES;
self.detailTextLabel.font = [UIFont boldSystemFontOfSize:12];
// self.selectionStyle = UITableViewCellSelectionStyleNone;
UIView *selectedView = [[UIView alloc] init];
selectedView.backgroundColor = [UIColor clearColor];
self.selectedBackgroundView = selectedView;
}
#pragma mark - Action
#pragma mark - Public Methods
@end

View File

@@ -0,0 +1,16 @@
//
// _ImageController.h
// Example_Objc
//
// Created by man 7/25/19.
// Copyright © 2020 man. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "_FileInfo.h"
@interface _ImageController : UIViewController
- (instancetype)initWithImage:(UIImage *)image fileInfo:(_FileInfo *)fileInfo;
@end

View File

@@ -0,0 +1,126 @@
//
// _ImageController.m
// Example_Objc
//
// Created by man 7/25/19.
// Copyright © 2020 man. All rights reserved.
//
#import "_ImageController.h"
#import "_Sandboxer.h"
@interface _ImageController () <UIDocumentInteractionControllerDelegate>
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIImage *image;
@property (nonatomic, strong) _FileInfo *fileInfo;
@property (nonatomic, strong) UIDocumentInteractionController *documentInteractionController;
@property (nonatomic, assign) BOOL flag;
@end
@implementation _ImageController
#pragma mark - Getters
- (UIDocumentInteractionController *)documentInteractionController {
if (!_documentInteractionController) {
_documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:self.fileInfo.URL];
_documentInteractionController.delegate = self;
_documentInteractionController.name = self.fileInfo.displayName;
}
return _documentInteractionController;
}
#pragma mark - init
- (instancetype)initWithImage:(UIImage *)image fileInfo:(_FileInfo *)fileInfo {
if (self = [super init]) {
self.image = image;
self.fileInfo = fileInfo;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
if ([_Sandboxer shared].isShareable) {
UIBarButtonItem *shareItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(sharingAction)];
self.navigationItem.rightBarButtonItem = shareItem;
}
self.view.backgroundColor = [UIColor whiteColor];
self.title = self.fileInfo.displayName;
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.image.size.width, self.image.size.height)];
self.imageView.center = CGPointMake(self.view.center.x, self.view.center.y - self.navigationController.navigationBar.frame.size.height - [[UIApplication sharedApplication] statusBarFrame].size.height);
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
self.imageView.image = self.image;
[self.view addSubview:self.imageView];
}
#pragma mark - touchesBegan
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
self.flag = !self.flag;
if (self.flag)
{
[self.navigationController setNavigationBarHidden:YES animated:YES];
[UIView animateWithDuration:UINavigationControllerHideShowBarDuration animations:^{
self.imageView.center = CGPointMake(self.view.center.x, self.view.center.y);
self.view.backgroundColor = [UIColor blackColor];
}];
}
else
{
[self.navigationController setNavigationBarHidden:NO animated:YES];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
[UIView animateWithDuration:UINavigationControllerHideShowBarDuration animations:^{
self.imageView.center = CGPointMake(self.view.center.x, self.view.center.y - 111);
self.view.backgroundColor = [UIColor whiteColor];
}];
}
else
{
BOOL iPhoneX = NO;
if (@available(iOS 11.0, *)) {
UIWindow *mainWindow = [[UIApplication sharedApplication] keyWindow];
if (mainWindow.safeAreaInsets.top > 24.0) {
iPhoneX = YES;
}
}
[UIView animateWithDuration:UINavigationControllerHideShowBarDuration animations:^{
self.imageView.center = CGPointMake(self.view.center.x, self.view.center.y - (iPhoneX ? 132 : 96));
self.view.backgroundColor = [UIColor whiteColor];
}];
}
}
}
#pragma mark - UIDocumentInteractionControllerDelegate
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
return self.navigationController;
}
- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller {
return self.view.bounds;
}
- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller {
return self.view;
}
#pragma mark - target action
- (void)sharingAction {
if (![_Sandboxer shared].isShareable) { return; }
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
[self.documentInteractionController presentOptionsMenuFromBarButtonItem:self.navigationItem.rightBarButtonItem animated:YES];
} else {
[self.documentInteractionController presentOptionsMenuFromRect:CGRectZero inView:self.view animated:YES];
}
}
@end

View File

@@ -0,0 +1,17 @@
//
// Example
// man
//
// Created by man 11/11/2018.
// Copyright © 2020 man. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface _ImageResources : NSObject
+ (UIImage * _Nullable)imageNamed:(NSString * _Nonnull)imageName;
+ (UIImage * _Nullable)fileTypeImageNamed:(NSString * _Nonnull)imageName;
@end

View File

@@ -0,0 +1,85 @@
//
// Example
// man
//
// Created by man 11/11/2018.
// Copyright © 2020 man. All rights reserved.
//
#import "_ImageResources.h"
@implementation _ImageResources
+ (UIImage * _Nullable)imageNamed:(NSString * _Nonnull)imageName {
return [self imageNamed:imageName fileType:@"png" inDirectory:nil];
}
+ (UIImage * _Nullable)fileTypeImageNamed:(NSString * _Nonnull)imageName {
return [self imageNamed:imageName fileType:@"png" inDirectory:nil];
}
+ (UIImage * _Nullable)imageNamed:(NSString * _Nonnull)imageName fileType:(NSString * _Nonnull)fileType inDirectory:(NSString * _Nullable)directory {
NSBundle *bundle = [NSBundle bundleForClass:self.class];
NSString *x1ImagePath = [bundle pathForResource:[self imageName:imageName appendingScale:1] ofType:fileType inDirectory:directory];
NSString *x2ImagePath = [bundle pathForResource:[self imageName:imageName appendingScale:2] ofType:fileType inDirectory:directory];
NSString *x3ImagePath = [bundle pathForResource:[self imageName:imageName appendingScale:3] ofType:fileType inDirectory:directory];
NSInteger scale = (NSInteger)[UIScreen mainScreen].scale;
NSString *imagePath;
switch (scale) {
case 1:
imagePath = x1ImagePath;
if (!imagePath) {
imagePath = x2ImagePath;
}
if (!imagePath) {
imagePath = x3ImagePath;
}
break;
case 2:
imagePath = x2ImagePath;
if (!imagePath) {
imagePath = x3ImagePath;
}
if (!imagePath) {
imagePath = x1ImagePath;
}
break;
case 3:
imagePath = x3ImagePath;
if (!imagePath) {
imagePath = x2ImagePath;
}
if (!imagePath) {
imagePath = x1ImagePath;
}
break;
default:
// default @1x
imagePath = x1ImagePath;
break;
}
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
return image;
}
#pragma mark - Private Methods
+ (NSString *)imageName:(NSString *)imageName appendingScale:(NSInteger)scale {
NSString *name;
if (scale == 1) {
name = imageName;
} else {
name = [NSString stringWithFormat:@"%@@%ldx", imageName, (long)scale];
}
return name;
}
@end

View File

@@ -0,0 +1,26 @@
//
// Example
// man
//
// Created by man 11/11/2018.
// Copyright © 2020 man. All rights reserved.
//
#ifndef _Sandboxer_Header_h
#define _Sandboxer_Header_h
/*
* System Versioning Preprocessor Macros
*/
#define _SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define _SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define _SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define _SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define _SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
#define _IsStringEmpty(string) (nil == string || (NSNull *)string == [NSNull null] || [@"" isEqualToString:string])
#define _IsStringNotEmpty(string) (string && (NSNull *)string != [NSNull null] && ![@"" isEqualToString:string])
#endif /* _Sandboxer_Header_h */

32
Pods/CocoaDebug/Sources/Sandbox/_Sandboxer.h generated Executable file
View File

@@ -0,0 +1,32 @@
//
// Example
// man
//
// Created by man 11/11/2018.
// Copyright © 2020 man. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface _Sandboxer : NSObject
@property (class, nonatomic, readonly, strong) _Sandboxer *shared;
@property (nonatomic, assign, getter=isSystemFilesHidden) BOOL systemFilesHidden; // Default is YES
@property (nonatomic, copy) NSURL *homeFileURL; // Default is Home Directory
@property (nonatomic, copy) NSString *homeTitle; // Default is `Home`
@property (nonatomic, assign, getter=isExtensionHidden) BOOL extensionHidden; // Default is NO
@property (nonatomic, assign, getter=isShareable) BOOL shareable; // Default is YES
@property (nonatomic, assign, getter=isFileDeletable) BOOL fileDeletable; // Default is NO
@property (nonatomic, assign, getter=isDirectoryDeletable) BOOL directoryDeletable; // Default is NO
- (instancetype)init __attribute__((unavailable("Use [_Sandboxer shared] or _Sandboxer.shared instead.")));
//liman
- (UINavigationController *)homeDirectoryNavigationController;
@end

80
Pods/CocoaDebug/Sources/Sandbox/_Sandboxer.m generated Executable file
View File

@@ -0,0 +1,80 @@
//
// Example
// man
//
// Created by man 11/11/2018.
// Copyright © 2020 man. All rights reserved.
//
#import "_Sandboxer.h"
#import "_DirectoryContentsTableViewController.h"
@interface _Sandboxer ()
@property (nonatomic, strong) UINavigationController *homeDirectoryNavigationController;
@end
@implementation _Sandboxer
@synthesize homeTitle = _homeTitle;
+ (_Sandboxer *)shared {
static _Sandboxer *_sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedInstance = [[_Sandboxer alloc] _init];
});
return _sharedInstance;
}
- (instancetype)_init {
if (self = [super init]) {
[self _config];
}
return self;
}
#pragma mark - Private Methods
- (void)_config {
_systemFilesHidden = YES;
_homeFileURL = [NSURL fileURLWithPath:NSHomeDirectory() isDirectory:YES];
_extensionHidden = NO;
_shareable = YES;
}
#pragma mark - Setters
- (void)setHomeTitle:(NSString *)title {
if (![_homeTitle isEqualToString:title]) {
_homeTitle = [title copy];
[[self.homeDirectoryNavigationController.viewControllers firstObject] setTitle:_homeTitle];
}
}
#pragma mark - Getters
- (NSString *)homeTitle {
if (nil == _homeTitle) {
_homeTitle = @"Sandbox";
}
return _homeTitle;
}
- (UINavigationController *)homeDirectoryNavigationController {
if (!_homeDirectoryNavigationController) {
_DirectoryContentsTableViewController *directoryContentsTableViewController = [[_DirectoryContentsTableViewController alloc] init];
directoryContentsTableViewController.homeDirectory = YES;
directoryContentsTableViewController.fileInfo = [[_FileInfo alloc] initWithFileURL:self.homeFileURL];
directoryContentsTableViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
_homeDirectoryNavigationController = [[UINavigationController alloc] initWithRootViewController:directoryContentsTableViewController];
}
return _homeDirectoryNavigationController;
}
@end

View File

@@ -0,0 +1,28 @@
//
// Example
// man
//
// Created by man 11/11/2018.
// Copyright © 2020 man. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface _SandboxerHelper : NSObject
+ (NSString *)fileModificationDateTextWithDate:(NSDate *)date;
//liman
//Get Folder Size
+ (NSString *)sizeOfFolder:(NSString *)folderPath;
//Get File Size
+ (NSString *)sizeOfFile:(NSString *)filePath;
+ (instancetype)sharedInstance;
+ (NSString *)generateRandomId;
@property (nonatomic, strong) NSMutableDictionary<NSString*, NSString*> *searchTextDictionary;
@end

View File

@@ -0,0 +1,81 @@
//
// Example
// man
//
// Created by man 11/11/2018.
// Copyright © 2020 man. All rights reserved.
//
#import "_SandboxerHelper.h"
@implementation _SandboxerHelper
+ (NSDateFormatter *)fileModificationDateFormatter {
static NSDateFormatter *_fileModificationDateFormatter;
if (!_fileModificationDateFormatter) {
_fileModificationDateFormatter = [[NSDateFormatter alloc] init];
_fileModificationDateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss.SSS";
}
return _fileModificationDateFormatter;
}
#pragma mark - Public Methods
+ (instancetype)sharedInstance {
static id sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
+ (NSString *)fileModificationDateTextWithDate:(NSDate *)date {
if (!date) { return @""; }
return [[_SandboxerHelper fileModificationDateFormatter] stringFromDate:date];
}
//liman
//Get Folder Size
+ (NSString *)sizeOfFolder:(NSString *)folderPath {
//Calculate Folder Size with only files
// NSArray *folderContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:folderPath error:nil];
//Calculate Folder Size with other sub directories in the folder
NSArray *folderContents = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:folderPath error:nil];
__block unsigned long long int folderSize = 0;
[folderContents enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[folderPath stringByAppendingPathComponent:obj] error:nil];
folderSize += [[fileAttributes objectForKey:NSFileSize] intValue];
}];
NSString *folderSizeStr = [NSByteCountFormatter stringFromByteCount:folderSize countStyle:NSByteCountFormatterCountStyleFile];
return folderSizeStr;
}
//Get File Size
+ (NSString *)sizeOfFile:(NSString *)filePath {
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
NSInteger fileSize = [[fileAttributes objectForKey:NSFileSize] integerValue];
NSString *fileSizeString = [NSByteCountFormatter stringFromByteCount:fileSize countStyle:NSByteCountFormatterCountStyleFile];
return fileSizeString;
}
#pragma mark - tool
+ (NSString *)generateRandomId {
UInt64 time = [[NSDate date] timeIntervalSince1970] * 1000;
return [NSString stringWithFormat:@"%llu_%@", time, [self generateRandomString]];
}
+ (NSString *)generateRandomString {
char data[10];
for (int x = 0; x < 10; ++x) {
data[x] = (char)('A' + (arc4random_uniform(26)));
}
return [[NSString alloc] initWithBytes:data length:10 encoding:NSUTF8StringEncoding];
}
@end