CCAdvanced.m 27 KB

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