CCAdvanced.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. //
  2. // CCManageHelp.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 06/11/15.
  6. // Copyright (c) 2017 Marino Faggiana. 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 "CCAdvanced.h"
  24. #import "CCUtility.h"
  25. #import "AppDelegate.h"
  26. #import <KTVHTTPCache/KTVHTTPCache.h>
  27. #import "NCBridgeSwift.h"
  28. @interface CCAdvanced ()
  29. {
  30. AppDelegate *appDelegate;
  31. }
  32. @end
  33. @implementation CCAdvanced
  34. -(id)init
  35. {
  36. XLFormDescriptor *form ;
  37. XLFormSectionDescriptor *section;
  38. XLFormRowDescriptor *row;
  39. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  40. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  41. form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_advanced_", nil)];
  42. // Section ACTIVITY -------------------------------------------------
  43. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_activity_", nil)];
  44. [form addFormSection:section];
  45. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"activityVerboseHigh" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_help_activity_verbose_", nil)];
  46. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  47. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"activityHigh"] multiplier:2 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  48. if ([CCUtility getActivityVerboseHigh]) row.value = @"1";
  49. else row.value = @"0";
  50. [section addFormRow:row];
  51. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sendMailActivity" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_help_activity_mail_", nil)];
  52. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  53. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  54. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  55. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"mail"] multiplier:2 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  56. row.action.formSelector = @selector(sendMail:);
  57. [section addFormRow:row];
  58. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"clearActivityLog" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_help_activity_clear_", nil)];
  59. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  60. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  61. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  62. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"delete"] multiplier:2 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  63. row.action.formSelector = @selector(clearActivity:);
  64. [section addFormRow:row];
  65. // Section HIDDEN FILES -------------------------------------------------
  66. section = [XLFormSectionDescriptor formSection];
  67. [form addFormSection:section];
  68. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"showHiddenFiles" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_show_hidden_files_", nil)];
  69. if ([CCUtility getShowHiddenFiles]) row.value = @"1";
  70. else row.value = @"0";
  71. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  72. [section addFormRow:row];
  73. // Format Compatibility
  74. section = [XLFormSectionDescriptor formSection];
  75. [form addFormSection:section];
  76. section.footerTitle = NSLocalizedString(@"_format_compatibility_footer_", nil);
  77. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"formatCompatibility" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_format_compatibility_", nil)];
  78. if ([CCUtility getFormatCompatibility]) row.value = @"1";
  79. else row.value = @"0";
  80. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  81. [section addFormRow:row];
  82. // Section : Files App --------------------------------------------------------------
  83. if (![NCBrandOptions sharedInstance].disable_openin_file) {
  84. section = [XLFormSectionDescriptor formSection];
  85. [form addFormSection:section];
  86. section.footerTitle = NSLocalizedString(@"_disable_files_app_footer_", nil);
  87. // Disable Files App
  88. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"disablefilesapp" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_disable_files_app_", nil)];
  89. if ([CCUtility getDisableFilesApp]) row.value = @"1";
  90. else row.value = @"0";
  91. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  92. [section addFormRow:row];
  93. }
  94. // Section CLEAR CACHE -------------------------------------------------
  95. section = [XLFormSectionDescriptor formSection];
  96. [form addFormSection:section];
  97. // Clear cache
  98. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"azzeracache" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_clear_cache_no_size_", nil)];
  99. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  100. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  101. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  102. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"delete"] multiplier:2 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
  103. row.action.formSelector = @selector(clearCache:);
  104. [section addFormRow:row];
  105. // Section EXIT --------------------------------------------------------
  106. section = [XLFormSectionDescriptor formSection];
  107. [form addFormSection:section];
  108. // Exit
  109. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"esci" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_exit_", nil)];
  110. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  111. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  112. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  113. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"exit"] multiplier:2 color:[UIColor redColor]] forKey:@"imageView.image"];
  114. row.action.formSelector = @selector(exitNextcloud:);
  115. [section addFormRow:row];
  116. return [super initWithForm:form];
  117. }
  118. - (void)viewDidLoad
  119. {
  120. [super viewDidLoad];
  121. _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  122. }
  123. // Apparirà
  124. - (void)viewWillAppear:(BOOL)animated
  125. {
  126. [super viewWillAppear:animated];
  127. self.tableView.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
  128. self.tableView.showsVerticalScrollIndicator = NO;
  129. // Color
  130. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  131. [appDelegate aspectTabBar:self.tabBarController.tabBar hidden:NO];
  132. //[self recalculateSize];
  133. }
  134. - (void)changeTheming
  135. {
  136. if (self.isViewLoaded && self.view.window)
  137. [appDelegate changeTheming:self];
  138. }
  139. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  140. {
  141. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  142. if ([rowDescriptor.tag isEqualToString:@"activityVerboseHigh"]) {
  143. [CCUtility setActivityVerboseHigh:[[rowDescriptor.value valueData] boolValue]];
  144. // Clear Date read Activity for force reload datasource
  145. appDelegate.activeActivity.storeDateFirstActivity = nil;
  146. }
  147. if ([rowDescriptor.tag isEqualToString:@"showHiddenFiles"]) {
  148. [CCUtility setShowHiddenFiles:[[rowDescriptor.value valueData] boolValue]];
  149. // force reload
  150. [[NCManageDatabase sharedInstance] setClearAllDateReadDirectory];
  151. }
  152. if ([rowDescriptor.tag isEqualToString:@"formatCompatibility"]) {
  153. [CCUtility setFormatCompatibility:[[rowDescriptor.value valueData] boolValue]];
  154. }
  155. if ([rowDescriptor.tag isEqualToString:@"disablefilesapp"]) {
  156. [CCUtility setDisableFilesApp:[[rowDescriptor.value valueData] boolValue]];
  157. }
  158. }
  159. #pragma --------------------------------------------------------------------------------------------
  160. #pragma mark === Mail ===
  161. #pragma --------------------------------------------------------------------------------------------
  162. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  163. {
  164. switch (result)
  165. {
  166. case MFMailComposeResultCancelled:
  167. [appDelegate messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode: error.code];
  168. break;
  169. case MFMailComposeResultSaved:
  170. [appDelegate messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode: error.code];
  171. break;
  172. case MFMailComposeResultSent:
  173. [appDelegate messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode: error.code];
  174. break;
  175. case MFMailComposeResultFailed: {
  176. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  177. [appDelegate messageNotification:@"_error_" description:msg visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode: error.code];
  178. }
  179. break;
  180. default:
  181. break;
  182. }
  183. // Close the Mail Interface
  184. [self dismissViewControllerAnimated:YES completion:NULL];
  185. }
  186. - (void)sendMail:(XLFormRowDescriptor *)sender
  187. {
  188. [self deselectFormRow:sender];
  189. // Email Subject
  190. NSString *emailTitle = NSLocalizedString(@"_information_req_", nil);
  191. // Email Content
  192. NSString *messageBody;
  193. // File Attachment
  194. NSString *fileAttachment = @"";
  195. // Email Recipents
  196. NSArray *toRecipents;
  197. NSArray *activities = [[NCManageDatabase sharedInstance] getActivityWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", appDelegate.activeAccount]];
  198. if ([activities count] == 0) {
  199. [appDelegate messageNotification:@"_info_" description:@"No activity found" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  200. return;
  201. }
  202. for (tableActivity *activity in activities) {
  203. NSString *date, *type, *actionFile, *note;
  204. date = [[NSDateFormatter localizedStringFromDate:activity.date dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterMediumStyle] stringByPaddingToLength:22 withString:@" " startingAtIndex:0];
  205. if ([activity.type isEqual: k_activityTypeInfo]) type = @"Info ";
  206. if ([activity.type isEqual: k_activityTypeSuccess]) type = @"Success";
  207. if ([activity.type isEqual: k_activityTypeFailure]) type = @"Failure";
  208. actionFile = [[NSString stringWithFormat:@"%@ %@", activity.action, activity.file] stringByPaddingToLength:100 withString:@" " startingAtIndex:0];
  209. if (activity.idActivity == 0) note = [NSString stringWithFormat:@"%@ Selector: %@", activity.note, activity.selector];
  210. else note = activity.note;
  211. note = [note stringByPaddingToLength:200 withString:@" " startingAtIndex:0];
  212. fileAttachment = [fileAttachment stringByAppendingString:[NSString stringWithFormat:@"| %@ | %@ | %@ | %@ |\n", date, type, actionFile, note]];
  213. }
  214. messageBody = [NSString stringWithFormat:@"\n\n\n%@ Version %@ (%@)", [NCBrandOptions sharedInstance].brand, [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  215. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  216. NSString *documentsDirectory = [paths objectAtIndex:0];
  217. NSError *error;
  218. // fix CCAdvanced.m line 276 2.17.2 (00005)
  219. if ([fileAttachment writeToFile:[documentsDirectory stringByAppendingPathComponent:@"activity.txt"] atomically:YES encoding:NSUTF8StringEncoding error:&error] && [MFMailComposeViewController canSendMail]) {
  220. toRecipents = [NSArray arrayWithObject:[NCBrandOptions sharedInstance].mailMe];
  221. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  222. mc.mailComposeDelegate = self;
  223. [mc setSubject:emailTitle];
  224. [mc setMessageBody:messageBody isHTML:NO];
  225. [mc setToRecipients:toRecipents];
  226. NSData *noteData = [NSData dataWithContentsOfFile:[documentsDirectory stringByAppendingPathComponent:@"activity.txt"]];
  227. [mc addAttachmentData:noteData mimeType:@"text/plain" fileName:@"activity.txt"];
  228. // Present mail view controller on screen
  229. [self presentViewController:mc animated:YES completion:NULL];
  230. } else {
  231. [appDelegate messageNotification:@"_error_" description:@"Impossible create file body" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  232. }
  233. }
  234. #pragma --------------------------------------------------------------------------------------------
  235. #pragma mark === Clear Activity ===
  236. #pragma --------------------------------------------------------------------------------------------
  237. - (void)clearActivity:(XLFormRowDescriptor *)sender
  238. {
  239. [self deselectFormRow:sender];
  240. [[NCManageDatabase sharedInstance] clearTable:[tableActivity class] account:appDelegate.activeAccount];
  241. [appDelegate.activeActivity reloadDatasource];
  242. }
  243. #pragma --------------------------------------------------------------------------------------------
  244. #pragma mark === Clear Cache ===
  245. #pragma --------------------------------------------------------------------------------------------
  246. - (void)removeAllFilesWithDB:(BOOL)withDB
  247. {
  248. [appDelegate maintenanceMode:YES];
  249. [self.hud visibleHudTitle:NSLocalizedString(@"_remove_cache_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  250. if (withDB) {
  251. [appDelegate.netQueue cancelAllOperations];
  252. }
  253. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC),dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  254. [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorage] error:nil];
  255. [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryUserData] error:nil];
  256. [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryScan] error:nil];
  257. [self emptyDocumentsDirectory];
  258. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  259. for (NSString *file in tmpDirectory)
  260. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  261. [KTVHTTPCache cacheDeleteAllCaches];
  262. //[self recalculateSize];
  263. // Clear Database
  264. [[NCManageDatabase sharedInstance] clearTable:[tableLocalFile class] account:appDelegate.activeAccount];
  265. if (withDB) {
  266. [[NCManageDatabase sharedInstance] clearTable:[tableActivity class] account:appDelegate.activeAccount];
  267. [[NCManageDatabase sharedInstance] clearTable:[tableCapabilities class] account:appDelegate.activeAccount];
  268. [[NCManageDatabase sharedInstance] clearTable:[tableDirectory class] account:appDelegate.activeAccount];
  269. [[NCManageDatabase sharedInstance] clearTable:[tableE2eEncryption class] account:appDelegate.activeAccount];
  270. [[NCManageDatabase sharedInstance] clearTable:[tableExternalSites class] account:appDelegate.activeAccount];
  271. [[NCManageDatabase sharedInstance] clearTable:[tableGPS class] account:nil];
  272. [[NCManageDatabase sharedInstance] clearTable:[tableMetadata class] account:appDelegate.activeAccount];
  273. [[NCManageDatabase sharedInstance] clearTable:[tablePhotos class] account:appDelegate.activeAccount];
  274. [[NCManageDatabase sharedInstance] clearTable:[tablePhotoLibrary class] account:appDelegate.activeAccount];
  275. [[NCManageDatabase sharedInstance] clearTable:[tableShare class] account:appDelegate.activeAccount];
  276. [[NCAutoUpload sharedInstance] alignPhotoLibrary];
  277. [appDelegate.filterFileID removeAllObjects];
  278. }
  279. [appDelegate maintenanceMode:NO];
  280. dispatch_async(dispatch_get_main_queue(), ^{
  281. // Close HUD
  282. [self.hud hideHud];
  283. // Inizialized home
  284. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
  285. });
  286. });
  287. }
  288. - (void)clearCache:(XLFormRowDescriptor *)sender
  289. {
  290. [self deselectFormRow:sender];
  291. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_delete_cache_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  292. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_yes_", nil)
  293. style:UIAlertActionStyleDefault
  294. handler:^(UIAlertAction *action) {
  295. [self removeAllFilesWithDB:NO];
  296. }]];
  297. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_cache_and_db_", nil)
  298. style:UIAlertActionStyleDefault
  299. handler:^(UIAlertAction *action) {
  300. [self removeAllFilesWithDB:YES];
  301. }]];
  302. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  303. }]];
  304. alertController.popoverPresentationController.sourceView = self.view;
  305. NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender];
  306. CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath];
  307. alertController.popoverPresentationController.sourceRect = CGRectOffset(cellRect, -self.tableView.contentOffset.x, -self.tableView.contentOffset.y);
  308. [self presentViewController:alertController animated:YES completion:nil];
  309. }
  310. /*
  311. - (void)recalculateSize
  312. {
  313. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  314. self.form.delegate = nil;
  315. XLFormRowDescriptor *rowAzzeraCache = [self.form formRowWithTag:@"azzeracache"];
  316. NSString *size = [CCUtility transformedSize:[[self getUserDirectorySize] longValue]];
  317. rowAzzeraCache.title = [NSString stringWithFormat:NSLocalizedString(@"_clear_cache_", nil), size];
  318. //rowAzzeraCache.title = NSLocalizedString(@"_clear_cache_no_size_", nil);
  319. [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  320. self.form.delegate = self;
  321. });
  322. }
  323. */
  324. #pragma --------------------------------------------------------------------------------------------
  325. #pragma mark == Exit Nextcloud ==
  326. #pragma --------------------------------------------------------------------------------------------
  327. - (void)exitNextcloud:(XLFormRowDescriptor *)sender
  328. {
  329. [self deselectFormRow:sender];
  330. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_exit_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  331. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  332. [self.hud visibleIndeterminateHud];
  333. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  334. [appDelegate.netQueue cancelAllOperations];
  335. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  336. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  337. [[CCNetworking sharedNetworking] invalidateAndCancelAllSession];
  338. [[NCManageDatabase sharedInstance] removeDB];
  339. [CCUtility deleteAllChainStore];
  340. [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorage] error:nil];
  341. [self emptyDocumentsDirectory];
  342. [self emptyLibraryDirectory];
  343. [self emptyGroupApplicationSupport];
  344. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  345. for (NSString *file in tmpDirectory)
  346. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  347. [self.hud hideHud];
  348. exit(0);
  349. });
  350. }]];
  351. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  352. }]];
  353. alertController.popoverPresentationController.sourceView = self.view;
  354. NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender];
  355. CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath];
  356. alertController.popoverPresentationController.sourceRect = CGRectOffset(cellRect, -self.tableView.contentOffset.x, -self.tableView.contentOffset.y);
  357. [self presentViewController:alertController animated:YES completion:nil];
  358. }
  359. #pragma --------------------------------------------------------------------------------------------
  360. #pragma mark == Utility ==
  361. #pragma --------------------------------------------------------------------------------------------
  362. - (void)emptyGroupApplicationSupport
  363. {
  364. NSString *file;
  365. NSURL *dirGroup = [CCUtility getDirectoryGroup];
  366. NSString *dirIniziale = [[dirGroup URLByAppendingPathComponent:k_appApplicationSupport] path];
  367. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  368. while (file = [enumerator nextObject])
  369. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  370. }
  371. - (void)emptyLibraryDirectory
  372. {
  373. NSString *file;
  374. NSString *dirIniziale;
  375. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
  376. dirIniziale = [paths objectAtIndex:0];
  377. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  378. while (file = [enumerator nextObject])
  379. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  380. }
  381. - (void)emptyDocumentsDirectory
  382. {
  383. NSString *file;
  384. NSString *dirIniziale;
  385. dirIniziale = [CCUtility getDirectoryDocuments];
  386. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  387. while (file = [enumerator nextObject])
  388. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  389. }
  390. - (NSNumber *)getUserDirectorySize
  391. {
  392. NSURL *directoryURL = [CCUtility getDirectoryGroup];
  393. unsigned long long count = 0;
  394. NSNumber *value = nil;
  395. if (! directoryURL) return 0;
  396. // Get dimension Document
  397. for (NSURL *url in [[NSFileManager defaultManager] enumeratorAtURL:directoryURL includingPropertiesForKeys:@[NSURLFileSizeKey] options:0 errorHandler:NULL]) {
  398. if ([url getResourceValue:&value forKey:NSURLFileSizeKey error:nil]) {
  399. count += [value longLongValue];
  400. } else {
  401. return nil;
  402. }
  403. }
  404. return @(count);
  405. }
  406. @end