CCMove.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. //
  2. // CCMove.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 04/09/14.
  6. // Copyright (c) 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCMove.h"
  24. #import "NCBridgeSwift.h"
  25. @interface CCMove ()
  26. {
  27. NSString *activeAccount;
  28. NSString *activePassword;
  29. NSString *activeUrl;
  30. NSString *activeUser;
  31. NSString *directoryUser;
  32. BOOL _isCryptoCloudMode;
  33. BOOL _loadingFolder;
  34. }
  35. @end
  36. @implementation CCMove
  37. // MARK: - View
  38. - (void)viewDidLoad
  39. {
  40. [super viewDidLoad];
  41. tableAccount *recordAccount = [[NCManageDatabase sharedInstance] getAccountActive];
  42. if (recordAccount) {
  43. activeAccount = recordAccount.account;
  44. activePassword = recordAccount.password;
  45. activeUrl = recordAccount.url;
  46. activeUser = recordAccount.user;
  47. directoryUser = [CCUtility getDirectoryActiveUser:activeUser activeUrl:activeUrl];
  48. // Crypto Mode
  49. if ([[CCUtility getKeyChainPasscodeForUUID:[CCUtility getUUID]] length] == 0) {
  50. _isCryptoCloudMode = NO;
  51. } else {
  52. _isCryptoCloudMode = YES;
  53. }
  54. } else {
  55. UIAlertController * alert= [UIAlertController alertControllerWithTitle:nil message:NSLocalizedString(@"_no_active_account_", nil) preferredStyle:UIAlertControllerStyleAlert];
  56. UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  57. [alert dismissViewControllerAnimated:YES completion:nil];
  58. }];
  59. [alert addAction:ok];
  60. [self presentViewController:alert animated:YES completion:nil];
  61. }
  62. [self.cancel setTitle:NSLocalizedString(@"_cancel_", nil)];
  63. [self.create setTitle:NSLocalizedString(@"_create_folder_", nil)];
  64. if (![_serverUrl length]) {
  65. _serverUrl = [CCUtility getHomeServerUrlActiveUrl:activeUrl];
  66. UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"navigationLogo"]];
  67. [self.navigationController.navigationBar.topItem setTitleView:image];
  68. self.title = @"Home";
  69. } else {
  70. UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0,0, self.navigationItem.titleView.frame.size.width, 40)];
  71. label.text = self.passMetadata.fileNamePrint;
  72. if (self.passMetadata.cryptated) label.textColor = NCBrandColor.sharedInstance.cryptocloud;
  73. else label.textColor = NCBrandColor.sharedInstance.navigationBarText;
  74. label.backgroundColor =[UIColor clearColor];
  75. label.textAlignment = NSTextAlignmentCenter;
  76. self.navigationItem.titleView=label;
  77. }
  78. // TableView : at the end of rows nothing
  79. self.tableView.tableFooterView = [UIView new];
  80. self.tableView.separatorColor = NCBrandColor.sharedInstance.seperator;
  81. self.tableView.emptyDataSetDelegate = self;
  82. self.tableView.emptyDataSetSource = self;
  83. // read file->folder
  84. [self readFileReloadFolder];
  85. }
  86. // Apparirà
  87. - (void)viewWillAppear:(BOOL)animated
  88. {
  89. [super viewWillAppear:animated];
  90. self.navigationController.navigationBar.barTintColor = NCBrandColor.sharedInstance.brand;
  91. self.navigationController.navigationBar.tintColor = NCBrandColor.sharedInstance.navigationBarText;
  92. self.navigationController.toolbar.barTintColor = NCBrandColor.sharedInstance.tabBar;
  93. self.navigationController.toolbar.tintColor = NCBrandColor.sharedInstance.brand;
  94. }
  95. // MARK: - alertView
  96. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  97. {
  98. if (buttonIndex == 1) {
  99. NSString *nome = [alertView textFieldAtIndex:0].text;
  100. if ([nome length]) {
  101. nome = [NSString stringWithFormat:@"%@/%@", _serverUrl, [CCUtility removeForbiddenCharactersServer:nome]];
  102. }
  103. }
  104. }
  105. #pragma --------------------------------------------------------------------------------------------
  106. #pragma mark ==== DZNEmptyDataSetSource ====
  107. #pragma --------------------------------------------------------------------------------------------
  108. - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
  109. {
  110. if (_loadingFolder)
  111. return NO;
  112. else
  113. return YES;
  114. }
  115. - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
  116. {
  117. return [UIColor whiteColor];
  118. }
  119. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
  120. {
  121. return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"filesNoFiles"] color:[NCBrandColor sharedInstance].brand];
  122. }
  123. - (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView
  124. {
  125. if (_loadingFolder) {
  126. UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
  127. activityView.transform = CGAffineTransformMakeScale(1.5f, 1.5f);
  128. activityView.color = [NCBrandColor sharedInstance].brand;
  129. [activityView startAnimating];
  130. return activityView;
  131. }
  132. return nil;
  133. }
  134. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
  135. {
  136. NSString *text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_files_no_files_", nil)];
  137. NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:[UIColor lightGrayColor]};
  138. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  139. }
  140. // MARK: - IBAction
  141. - (IBAction)cancel:(UIBarButtonItem *)sender
  142. {
  143. [self dismissViewControllerAnimated:YES completion:nil];
  144. }
  145. - (IBAction)move:(UIBarButtonItem *)sender
  146. {
  147. [_networkingOperationQueue cancelAllOperations];
  148. [self.delegate moveServerUrlTo:_serverUrl title:self.passMetadata.fileNamePrint];
  149. [self dismissViewControllerAnimated:YES completion:nil];
  150. }
  151. - (IBAction)create:(UIBarButtonItem *)sender
  152. {
  153. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_create_folder_",nil) message:@"" preferredStyle:UIAlertControllerStyleAlert];
  154. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  155. //textField.placeholder = NSLocalizedString(@"LoginPlaceholder", @"Login");
  156. }];
  157. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_save_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  158. [self createFolder:alertController.textFields.firstObject.text];
  159. }]];
  160. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  161. }]];
  162. [self presentViewController:alertController animated:YES completion:nil];
  163. }
  164. // MARK: - BKPasscodeViewController
  165. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  166. {
  167. [aViewController dismissViewControllerAnimated:YES completion:nil];
  168. [self performSegueDirectoryWithControlPasscode:false];
  169. }
  170. - (void)passcodeViewController:(BKPasscodeViewController *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  171. {
  172. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  173. self.lockUntilDate = nil;
  174. self.failedAttempts = 0;
  175. aResultHandler(YES);
  176. } else {
  177. aResultHandler(NO);
  178. }
  179. }
  180. - (void)passcodeViewControllerDidFailAttempt:(BKPasscodeViewController *)aViewController
  181. {
  182. self.failedAttempts++;
  183. if (self.failedAttempts > 5) {
  184. NSTimeInterval timeInterval = 60;
  185. if (self.failedAttempts > 6) {
  186. NSUInteger multiplier = self.failedAttempts - 6;
  187. timeInterval = (5 * 60) * multiplier;
  188. if (timeInterval > 3600 * 24) {
  189. timeInterval = 3600 * 24;
  190. }
  191. }
  192. self.lockUntilDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
  193. }
  194. }
  195. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(BKPasscodeViewController *)aViewController
  196. {
  197. return self.failedAttempts;
  198. }
  199. - (NSDate *)passcodeViewControllerLockUntilDate:(BKPasscodeViewController *)aViewController
  200. {
  201. return self.lockUntilDate;
  202. }
  203. - (void)passcodeViewCloseButtonPressed:(id)sender
  204. {
  205. [self dismissViewControllerAnimated:YES completion:nil];
  206. }
  207. // MARK: - NetWorking
  208. - (void)addNetworkingQueue:(CCMetadataNet *)metadataNet
  209. {
  210. OCnetworking *operation = [[OCnetworking alloc] initWithDelegate:self metadataNet:metadataNet withUser:activeUser withPassword:activePassword withUrl:activeUrl isCryptoCloudMode:_isCryptoCloudMode];
  211. _networkingOperationQueue.maxConcurrentOperationCount = k_maxConcurrentOperation;
  212. [_networkingOperationQueue addOperation:operation];
  213. }
  214. // MARK: - Download File
  215. - (void)downloadFileSuccess:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
  216. {
  217. if ([selector isEqualToString:selectorLoadPlist]) {
  218. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  219. metadata = [CCUtility insertInformationPlist:metadata directoryUser:directoryUser];
  220. metadata = [[NCManageDatabase sharedInstance] updateMetadata:metadata activeUrl:activeUrl];
  221. // se è un template aggiorniamo anche nel FileSystem
  222. if ([metadata.type isEqualToString: k_metadataType_template]) {
  223. [[NCManageDatabase sharedInstance] setLocalFileWithFileID:metadata.fileID date:metadata.date exifDate:nil exifLatitude:nil exifLongitude:nil fileName:nil fileNamePrint:metadata.fileNamePrint];
  224. }
  225. [self.tableView reloadData];
  226. }
  227. }
  228. - (void)downloadFileFailure:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode
  229. {
  230. self.move.enabled = NO;
  231. }
  232. // MARK: - Read Folder
  233. - (void)readFileFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  234. {
  235. [self readFolder];
  236. }
  237. - (void)readFileSuccess:(CCMetadataNet *)metadataNet metadata:(tableMetadata *)metadata
  238. {
  239. if ([metadataNet.selector isEqualToString:selectorReadFileReloadFolder]) {
  240. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND serverUrl = %@", metadataNet.account, metadataNet.serverUrl]];
  241. if ([metadata.etag isEqualToString:directory.etag] == NO) {
  242. [self readFolder];
  243. }
  244. }
  245. }
  246. - (void)readFileReloadFolder
  247. {
  248. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:activeAccount];
  249. metadataNet.action = actionReadFile;
  250. metadataNet.priority = NSOperationQueuePriorityHigh;
  251. metadataNet.selector = selectorReadFileReloadFolder;
  252. metadataNet.serverUrl = _serverUrl;
  253. [self addNetworkingQueue:metadataNet];
  254. }
  255. // MARK: - Read Folder
  256. - (void)readFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  257. {
  258. _loadingFolder = NO;
  259. self.move.enabled = NO;
  260. [self.tableView reloadData];
  261. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_",nil) message:message preferredStyle:UIAlertControllerStyleAlert];
  262. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  263. }]];
  264. [self presentViewController:alertController animated:YES completion:nil];
  265. }
  266. - (void)readFolderSuccess:(CCMetadataNet *)metadataNet metadataFolder:(tableMetadata *)metadataFolder metadatas:(NSArray *)metadatas
  267. {
  268. NSMutableArray *metadatasToInsertInDB = [NSMutableArray new];
  269. // Update directory etag
  270. [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:metadataNet.serverUrl serverUrlTo:nil etag:metadataFolder.etag];
  271. for (tableMetadata *metadata in metadatas) {
  272. // type of file
  273. NSInteger typeFilename = [CCUtility getTypeFileName:metadata.fileName];
  274. // do not insert crypto file
  275. if (typeFilename == k_metadataTypeFilenameCrypto) continue;
  276. // verify if the record encrypted has plist + crypto
  277. if (typeFilename == k_metadataTypeFilenamePlist && metadata.directory == NO) {
  278. BOOL isCryptoComplete = NO;
  279. NSString *fileNameCrypto = [CCUtility trasformedFileNamePlistInCrypto:metadata.fileName];
  280. for (tableMetadata *completeMetadata in metadatas) {
  281. if (completeMetadata.cryptated == NO) continue;
  282. else if ([completeMetadata.fileName isEqualToString:fileNameCrypto]) {
  283. isCryptoComplete = YES;
  284. break;
  285. }
  286. }
  287. if (isCryptoComplete == NO) continue;
  288. }
  289. // Insert in Array
  290. [metadatasToInsertInDB addObject:metadata];
  291. }
  292. // insert in Database
  293. metadatas = [[NCManageDatabase sharedInstance] addMetadatas:metadatasToInsertInDB activeUrl:activeUrl serverUrl:metadataNet.serverUrl];
  294. // Plist MULTI THREAD
  295. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  296. for (tableMetadata *metadata in metadatas) {
  297. if ([CCUtility isCryptoPlistString:metadata.fileName] && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileName]] == NO) {
  298. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:activeAccount];
  299. metadataNet.action = actionDownloadFile;
  300. metadataNet.downloadData = NO;
  301. metadataNet.downloadPlist = YES;
  302. metadataNet.fileID = metadata.fileID;
  303. metadataNet.selector = selectorLoadPlist;
  304. metadataNet.serverUrl = _serverUrl;
  305. metadataNet.session = k_download_session_foreground;
  306. metadataNet.taskStatus = k_taskStatusResume;
  307. [self addNetworkingQueue:metadataNet];
  308. }
  309. }
  310. });
  311. _loadingFolder = NO;
  312. [self.tableView reloadData];
  313. }
  314. - (void)readFolder
  315. {
  316. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:activeAccount];
  317. metadataNet.action = actionReadFolder;
  318. metadataNet.serverUrl = _serverUrl;
  319. metadataNet.selector = selectorReadFolder;
  320. metadataNet.date = nil;
  321. [self addNetworkingQueue:metadataNet];
  322. //
  323. _loadingFolder = YES;
  324. [self.tableView reloadData];
  325. }
  326. // MARK: - Create Folder
  327. - (void)createFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  328. {
  329. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_",nil) message:message preferredStyle:UIAlertControllerStyleAlert];
  330. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  331. }]];
  332. [self presentViewController:alertController animated:YES completion:nil];
  333. }
  334. - (void)createFolderSuccess:(CCMetadataNet *)metadataNet
  335. {
  336. (void)[[NCManageDatabase sharedInstance] addDirectoryWithServerUrl:[NSString stringWithFormat:@"%@/%@", metadataNet.serverUrl, metadataNet.fileName] permissions:@""];
  337. // Load Folder or the Datasource
  338. [self readFolder];
  339. }
  340. - (void)createFolder:(NSString *)fileNameFolder
  341. {
  342. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:activeAccount];
  343. fileNameFolder = [CCUtility removeForbiddenCharactersServer:fileNameFolder];
  344. if (![fileNameFolder length]) return;
  345. metadataNet.action = actionCreateFolder;
  346. metadataNet.fileName = fileNameFolder;
  347. metadataNet.selector = selectorCreateFolder;
  348. metadataNet.selectorPost = selectorReadFolderForced;
  349. metadataNet.serverUrl = _serverUrl;
  350. [self addNetworkingQueue:metadataNet];
  351. }
  352. // MARK: - Table
  353. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  354. {
  355. return 1;
  356. }
  357. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  358. {
  359. NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:_serverUrl];
  360. NSPredicate *predicate;
  361. if (self.onlyClearDirectory) predicate = [NSPredicate predicateWithFormat:@"account = %@ AND directoryID = %@ AND directory = true AND cryptated = false", activeAccount, directoryID];
  362. else predicate = [NSPredicate predicateWithFormat:@"account == %@ AND directoryID = %@ AND directory = true", activeAccount, directoryID];
  363. NSArray *result = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:predicate sorted:nil ascending:NO];
  364. if (result)
  365. return [result count];
  366. else
  367. return 0;
  368. }
  369. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  370. {
  371. NSPredicate *predicate;
  372. static NSString *CellIdentifier = @"MyCustomCell";
  373. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  374. if (cell == nil) {
  375. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
  376. }
  377. NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:_serverUrl];
  378. if (self.onlyClearDirectory) predicate = [NSPredicate predicateWithFormat:@"account = %@ AND directoryID = %@ AND directory = true AND cryptated = false", activeAccount, directoryID];
  379. else predicate = [NSPredicate predicateWithFormat:@"account = %@ AND directoryID = %@ AND directory = true", activeAccount, directoryID];
  380. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataAtIndexWithPredicate:predicate sorted:@"fileName" ascending:YES index:indexPath.row];
  381. // colors
  382. if (metadata.cryptated) {
  383. cell.textLabel.textColor = NCBrandColor.sharedInstance.cryptocloud;
  384. } else {
  385. cell.textLabel.textColor = [UIColor blackColor];
  386. }
  387. cell.detailTextLabel.text = @"";
  388. cell.imageView.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:metadata.iconName] color:[NCBrandColor sharedInstance].brand];
  389. cell.textLabel.text = metadata.fileNamePrint;
  390. return cell;
  391. }
  392. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  393. {
  394. [self performSegueDirectoryWithControlPasscode:YES];
  395. }
  396. // MARK: - Navigation
  397. - (void)performSegueDirectoryWithControlPasscode:(BOOL)controlPasscode
  398. {
  399. NSString *nomeDir;
  400. NSPredicate *predicate;
  401. NSIndexPath *index = [self.tableView indexPathForSelectedRow];
  402. NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:_serverUrl];
  403. if (self.onlyClearDirectory) predicate = [NSPredicate predicateWithFormat:@"account = %@ AND directoryID = %@ AND directory = true AND cryptated = false", activeAccount, directoryID];
  404. else predicate = [NSPredicate predicateWithFormat:@"account = %@ AND directoryID == %@ AND directory = true", activeAccount, directoryID];
  405. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataAtIndexWithPredicate:predicate sorted:@"fileName" ascending:YES index:index.row];
  406. if (metadata.errorPasscode == NO) {
  407. // lockServerUrl
  408. NSString *lockServerUrl = [CCUtility stringAppendServerUrl:_serverUrl addFileName:metadata.fileNameData];
  409. // Se siamo in presenza di una directory bloccata E è attivo il block E la sessione PASSWORD Lock è senza data ALLORA chiediamo la password per procedere
  410. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"serverUrl = %@", lockServerUrl]];
  411. if (directory.lock && [[CCUtility getBlockCode] length] && controlPasscode) {
  412. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  413. viewController.delegate = self;
  414. //viewController.fromType = CCBKPasscodeFromLockDirectory;
  415. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  416. viewController.inputViewTitlePassword = YES;
  417. if ([CCUtility getSimplyBlockCode]) {
  418. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  419. viewController.passcodeInputView.maximumLength = 6;
  420. } else {
  421. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  422. viewController.passcodeInputView.maximumLength = 64;
  423. }
  424. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  425. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  426. viewController.touchIDManager = touchIDManager;
  427. viewController.title = NSLocalizedString(@"_folder_blocked_", nil);
  428. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  429. viewController.navigationItem.leftBarButtonItem.tintColor = NCBrandColor.sharedInstance.cryptocloud;
  430. UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
  431. [self presentViewController:navController animated:YES completion:nil];
  432. return;
  433. }
  434. if (metadata.cryptated) nomeDir = [metadata.fileName substringToIndex:[metadata.fileName length]-6];
  435. else nomeDir = metadata.fileName;
  436. CCMove *viewController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMoveVC"];
  437. viewController.delegate = self.delegate;
  438. viewController.onlyClearDirectory = self.onlyClearDirectory;
  439. viewController.move.title = self.move.title;
  440. viewController.networkingOperationQueue = _networkingOperationQueue;
  441. viewController.passMetadata = metadata;
  442. viewController.serverUrl = [CCUtility stringAppendServerUrl:_serverUrl addFileName:nomeDir];
  443. [self.navigationController pushViewController:viewController animated:YES];
  444. }
  445. }
  446. @end